如何将 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
在尝试将 timepicker 设置为 mondayalarmtime 之前放置一个询问 mondayalarmtime 的 NSLog 返回相同的结果。
Mondays alarm time.. 2011-01-01 09:00:35 +0000
然后,当它尝试将 timepicker 日期设置为 mondayalarmtime 时,它会崩溃报告:
Program received signal: “EXC_BAD_ACCESS”.
I have tried various things, including:
[timepicker setDate: [NSDate mondayalarmtime]];
and
timepicker.date = mondayalarmtime;
Each time, this line crashes the simulator. My mondayalarmtime is defined in viewDidLoad here:
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;
The NSLog returns:
The input date 2011-01-01 09:00:00 +0000
Putting an NSLog asking for mondayalarmtime just before it tries to set thet imepicker to mondayalarmtime returns the same..
Mondays alarm time.. 2011-01-01 09:00:35 +0000
And then when it tries to set the timepicker date to mondayalarmtime, it crashes with the report:
Program received signal: “EXC_BAD_ACCESS”.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在向 NSDate 发送 mondayalarmtime 消息。 NSDate 不理解此消息
尝试使用 mondayalarmtime 设置属性并调用 getter
You are sending the mondayalarmtime message to NSDate. NSDate does not understand this message
Try setting a property with mondayalarmtime and calling the getter