2015-10-14 79 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];