我正在开发一个 iPhone 应用程序。我NSDateFormatter
用来格式化日期NSString
,然后我尝试将该日期字符串设置为UILabel
. 我试过这段代码:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm:ss"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:now];
Result: theDate:16/10/2012
但我收到一个错误:
UILabel *lbl = [[UILabel alloc]init];
lbl.text = theDate; // the error comes here
错误信息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray isEqualToString:]: unrecognized selector sent to instance 0x6b837e0'
*** First throw call stack: