Используя NSString как сообщение UIAlertView: - PullRequest
1 голос
/ 24 марта 2012

Я не могу понять, почему это не сработает, я попробовал 100 способов. AlertView отображается с пустым сообщением. Вот мой код:

eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

timeTillRest является строкой NSString. и непосредственно перед вызовом alertview NSLog(@"%@",timeTillRest); отображает строку без проблем.

Ответы [ 2 ]

2 голосов
/ 24 марта 2012

Зачем вам использовать alertview в качестве переменной экземпляра?В этом нет необходимости.Это так же просто, как это:

UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[eventChoiceNow show];
[eventChoiceNow release];
2 голосов
/ 24 марта 2012

Это должно работать просто отлично. Тестирование с использованием этого кода:

NSString *timeTillRest = @"Testing";

    UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [eventChoiceNow show];

И все работает отлично. Также тестирование с использованием:

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong) NSString *timeTillRest;
@end

@implementation ViewController
@synthesize timeTillRest;
- (void)viewDidLoad
{
    [super viewDidLoad];
    timeTillRest = @"Testing";

    UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [eventChoiceNow show];
    // Do any additional setup after loading the view, typically from a nib.
}

И это тоже работает безупречно. Убедитесь, что вы не устанавливаете это свойство в nil.

...