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

发布于 2024-10-10 06:57:27 字数 907 浏览 0 评论 0原文

我尝试过各种方法,包括:

[timepicker setDate: [NSDate mondayalarmtime]];

并且

timepicker.date = mondayalarmtime;

每次,这条线都会使模拟器崩溃。我的 mondayalarmtime 在 vi​​ewDidLoad 中定义如下:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-10-17 06:57:27

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

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

[timepicker setDate:[self mondayalarmtime]];

You are sending the mondayalarmtime message to NSDate. NSDate does not understand this message

Try setting a property with mondayalarmtime and calling the getter

[timepicker setDate:[self mondayalarmtime]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文