如果使用 UIModalPresentationFormSheet 呈现模型,如何在子视图上重新加载数据
我在 iPad 应用程序中实现了 UIModalPresentationFormSheet。新视图部分覆盖子视图并允许用户做出选择。然而,这一切都很好...
当用户选择一个选项时,我想用新的详细信息更新底层视图,但无法让它工作!
我尝试过使用 setNeedsDisplay 或 [table reloadData];在 viewDidAppear 和 viewWillAppear 方法中。
为了代码的缘故,一些代码:
- (void)viewWillAppear:(BOOL)animated {
[self updateUserDetails];
[self.myTableView reloadData];
}
- (void)viewDidAppear:(BOOL)animated {
[self updateUserDetails];
[self.myTableView reloadData];
}
- (void)updateUserDetails {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:selection forKey:@"userDetail"];
}
我的转换如下。如果此行被注释掉,则应用程序将按预期运行:
myNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
任何帮助表示赞赏,谢谢!
I have implemented a UIModalPresentationFormSheet in my iPad application. The new view partially covers the sub view and allows the user to make a choice. This all works great, however...
When the user selects an option I would like to update the underlying view with the new details, but cannot get it to work!
I have tried using setNeedsDisplay or [table reloadData]; in both the viewDidAppear and viewWillAppear methods.
Some code for codes sake:
- (void)viewWillAppear:(BOOL)animated {
[self updateUserDetails];
[self.myTableView reloadData];
}
- (void)viewDidAppear:(BOOL)animated {
[self updateUserDetails];
[self.myTableView reloadData];
}
- (void)updateUserDetails {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:selection forKey:@"userDetail"];
}
My transition is as follows. If this line is commented out then the application functions as expected:
myNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
Any help appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置
self.view.autolayoutSubviews = NO;
UI 将更改 UIModalPresentationFormSheet 视图的大小。这可能会破坏重新加载过程。
You can set
self.view.autolayoutSubviews = NO;
UI will change your view's size for UIModalPresentationFormSheet. This may be break the reload process.
我认为您应该将数据的重新加载放在检测用户选择的代码附近,而不是在
viewDidAppear
的viewWillAppear
中。I think you should put the reloading of data near the code where you detect the selection of the user, not in the
viewWillAppear
ofviewDidAppear
.