2015-10-14 81 views
0

当警示框被点击时,我面临错误。错误是与String不兼容的数组指针。如何在警示框上显示日期和时间

2015-10-14 12:41:06.235 snadwitch2[1974:56154] -[__NSArrayI length]: unrecognized selector sent to instance 0x7f954e918e60 
    2015-10-14 12:41:06.239 snadwitch2[1974:56154] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7f954e918e60' 

的警告框代码

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wait" message:@ [@"The current date and time is: %@", [NSDate date]] delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel",nil]; 
     [alert show]; 

回答

5

你传递一个数组而不是字符串。您需要:

NSString *message = [NSString stringWithFormat:@"The current date and time is: %@", [NSDate date]]; 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wait" 
    message:message 
    delegate:self 
    cancelButtonTitle:@"Delete" 
    otherButtonTitles:@"Cancel",nil]; 
[alert show]; 
相关问题