One UIDatePicker for multiple fields - EXC_BAD_ACCESS when setting the date

余生颓废 提交于 2019-12-13 03:52:15

问题


I have a single UIDatePicker view which is being used for a number of different date values.

An example use case for it failing is:

  1. User brings up the date picker and changes the date.
  2. User tries to bring up the date picker again and it crashes.

If the user opens the date picker, but closes it without changing the date, it's fine, and the user can then open the date picker again.

Just before the date picker is opened I run the following code:

datePicker.datePickerMode = UIDatePickerModeTime;
datePicker.date = current.time;
[datePicker removeTarget:nil action:NULL forControlEvents:UIControlEventValueChanged];
[datePicker addTarget:self action:@selector(currentTimeChanged:) forControlEvents:UIControlEventValueChanged];
[app.window addSubview:datePickerContainerView];

currentTimeChanged simply calls current.time = datePicker.date

I have tried running with zombies enabled, and also running with instruments, but for some reason it's not coming back with anything. edit: I should clarify, by "anything", I mean no "zombie detected" message is appearing in instruments, the app just crashes back to springboard.

According to the debugger the error happens in datePicker setDate, and more specifically CFNumberGetValue - if that means anything...

Update: this issue only occurs in the simulator - when I run it on my device it's fine. Can I put it down to just being the simulator?

来源:https://stackoverflow.com/questions/10538807/one-uidatepicker-for-multiple-fields-exc-bad-access-when-setting-the-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!