UIDatePicker与UIApplicationSignificantTimeChangeNotification [英] UIDatePicker vs. UIApplicationSignificantTimeChangeNotification
问题描述
我正在处理我的应用程序中的 UIApplicationSignificantTimeChangeNotification ,当午夜到来时,该应用程序中的所有其他屏幕都会正常刷新.我遇到问题的是 UIDatePicker . UIPickerView 具有 refreshAllComponents 方法,该方法在另一个屏幕上用于对午夜更改进行更新.我想为 UIDatePicker 设置相同的名称,但很遗憾,我找不到刷新它的方法,尽管 Today 仍然是 Today ,尽管已经是昨天了.有办法吗?
I'm handling UIApplicationSignificantTimeChangeNotification in my app and all the other screens in the app are gracefully refreshed when midnight comes. The one I have trouble with is with UIDatePicker. UIPickerView has refreshAllComponents method which I use in another screen to make an update on midnight change. I would like to have the same for UIDatePicker, but unfortunately I couldn't find a way to refresh it, and Today remains Today, although it is already Yesterday. Any way out?
推荐答案
为什么不用新实例替换UIDatePicker?
Why not replace the UIDatePicker with new instance?
UIDatePicker *oldPicker = self.myDatePicker;
UIDatePicker *newPicker = [[UIDatePicker alloc] initWithFrame:oldPicker.frame];
[newPicker setDate:oldPicker.date animated:NO];
[[oldPicker superview] addSubview:newPicker];
[oldPicker removeFromSuperview];
self.myDatePicker = newPicker;
[newPicker release];
上面的代码将oldPicker交换为newPicker,复制设置,因此没有人会注意到更改.如果您还有其他对Picker视图的引用,则也需要对其进行更新.
The above code will swap oldPicker for newPicker, copying settings so no one will notice the change. If you have other references to the picker view, you'll need to update them, too.
这篇关于UIDatePicker与UIApplicationSignificantTimeChangeNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!