如何显示日期和警报框上的时间

时间:2015-10-14 07:17:17

标签: ios objective-c xcode

点击警告框时,我遇到错误。错误是与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];

1 个答案:

答案 0 :(得分: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];