我尝试了多种方法,包括:
[timepicker setDate: [NSDate mondayalarmtime]];
并且
timepicker.date = mondayalarmtime;
每次执行时,这行代码都会导致模拟器崩溃。我的mondayalarmtime在viewDidLoad中定义如下:
NSDateFormatter *inputFormat = [[NSDateFormatter alloc] init];
[inputFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *inputDate = [inputFormat dateFromString: @"2011-01-01 09:00:00"];
NSLog (@"The input date %@", inputDate);
NSDate *mondayalarmtime = inputDate;
NSLog返回:
The input date 2011-01-01 09:00:00 +0000
在尝试将时间选择器设置为mondayalarmtime之前,放置一个要求mondayalarmtime的NSLog会返回相同的结果。
Mondays alarm time.. 2011-01-01 09:00:35 +0000
然后当它试图将时间选择器的日期设置为mondayalarmtime时,它会崩溃并报告以下错误:
Program received signal: “EXC_BAD_ACCESS”.