這應該工作得很好。使用此代碼測試:
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.
}
而且,這工作也完美無瑕。確保你沒有將該屬性設置爲零。
您是否100%確定'timeTillRest'是一個'NSString'?只是想知道爲什麼這不起作用,因爲這是'UIAlertView'最簡單的用例。僅供參考,'%@'也可以與除NSString之外的Foundation類一起使用。怎麼樣'NSLog(@「%@」,NSStringFromClass([timeTillRest class]));'? – ayoy 2012-03-24 15:22:38
我確信'@property(nonatomic,strong)NSString * timeTillRest;'在我的.h中,它也是在我的.m中合成的。 – 2012-03-24 15:29:17
你在哪裏定義你的「UIAlertView * eventChoiceNow」?嘗試在這個代碼中定義自己寫的地方。 – 2012-03-24 15:42:22