iOS 4.3 和 5.0 之间 UIDatePicker 代码执行的不同行为
我在尝试找出运行 iOS 5.0 的 iPhone 4S 和运行 iOS 4.3 的 iPad 上相同代码的不同行为时遇到了一个令人困惑的问题。
视图控制器代码与带有日期选择器的视图相关联,以输入出生日期。通过 Interface Builder,日期选择器与接收到的操作“值已更改”相关联,该操作定向到视图控制器方法 -(IBAction)birthDate: (id)sender:
-(IBAction)birthDate: (id)sender {
//Code here executed when date of birth entered. Should not be executed when view loads.
}
在应用程序中,在视图加载时不执行此代码非常重要。我已经通过断点插入证明,当视图加载 iOS 5.0 时,此代码不会执行,但会在视图加载 iOS 4.3 时执行,从而导致程序出现真正的问题(默认出生日期被解释为输入的出生日期) 。我非常感谢有关如何防止 IBAction 代码在 iOS 4.3 中执行的建议,除非用户更改默认出生日期。我也很好奇为什么会存在这种行为差异。提前致谢。
I have a perplexing problem in trying to sort out different behavior of the same code on an iPhone 4S running iOS 5.0 and an iPad running iOS 4.3.
The view controller code is associated with a view with a date picker to enter a date of birth. Via Interface Builder the date picker is associated with the received action "Value Changed" directed toward the view controller method -(IBAction)birthDate: (id)sender:
-(IBAction)birthDate: (id)sender {
//Code here executed when date of birth entered. Should not be executed when view loads.
}
It is very important in the app that this code NOT be executed when the view loads. I have demonstrated with a breakpoint insertion that this code does not execute when the view loads with iOS 5.0, but does execute when the view loads with iOS 4.3, causing a real problem with the program (the default birthdate becomes interpreted as an entered birthdate). I very much would appreciate advice on how to prevent the IBAction code from executing in iOS 4.3 unless the user changes the default date of birth. I also am very curious as to why this difference in behavior should exist. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 iOS 5.0 中 UIPickerView 行为的记录更改 (发行说明)
在 iOS 4.3 上解决这个问题的一种方法是在
loadView
的开头将 BOOL 设置为 YES,在结尾设置为 NO。然后,您的值更改方法
birthDate:
可以在处理更改之前检查此 BOOL 值是否为 NO。This is a documented change to UIPickerView's behaviour in iOS 5.0 (Release Notes)
One way to get around it on iOS 4.3 would be to have a BOOL that is set to YES at the beginning of
loadView
and NO at the end.Your value changed method
birthDate:
could then check that this BOOL value is NO before handling the change.