如何将UIDatePicker日期设置为另一个日期?

时间:2011-01-03 15:06:37

标签: iphone cocoa-touch nsdate uidatepicker

我尝试过各种各样的事情,包括:

[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

在尝试将imepicker设置为mondayalarmtime之前,让NSLog请求mondayalarmtime返回相同的内容..

Mondays alarm time.. 2011-01-01 09:00:35 +0000

然后当它尝试将timepicker日期设置为mondayalarmtime时,它会与报告崩溃:

Program received signal:  “EXC_BAD_ACCESS”.

1 个答案:

答案 0 :(得分:6)

您正在向NSDate发送mondayalarmtime消息。 NSDate不理解此消息

尝试使用mondayalarmtime设置属性并调用getter

[timepicker setDate:[self mondayalarmtime]];