Ios 如何显示日期&;时间警报框

Ios 如何显示日期&;时间警报框,ios,objective-c,xcode,Ios,Objective C,Xcode,单击警报框时,我面临错误。错误是数组指针与字符串不兼容 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 'N

单击警报框时,我面临错误。错误是数组指针与字符串不兼容

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];

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

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];

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

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];