UIDatePicker vs. UIApplicationSignificantTimeChangeNotification

回眸只為那壹抹淺笑 提交于 2019-12-06 06:02:11

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];

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.

You can refresh the UIDatePicker using its method

- (void)setDate:(NSDate *)date animated:(BOOL)animated

Simply pass as the date argument [NSDate date] and YES as the animated argument. This should work since after midnight [NSDate date] must produce the correct current date.

This is a pretty old topic, but as I found it with google, so will other people. What worked for me :

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