从 DetailView 重新加载 MasterView 中的数据

发布于 2024-11-17 13:03:53 字数 611 浏览 3 评论 0原文

我之前在 iPhone 上遇到了类似的问题,但相同的解决方案似乎不适用于 iPad 环境。我的目标是调用在 RootViewController 中定义的方法 forceReload,一旦模态被关闭,它将从 DetailView 重新加载 RootView 中的 countdown_table 数据。当直接从 RootViewController 调用时,forceReload 工作正常,但我似乎无法从 DetailView 指向 RootViewController。

我尝试过使用

RootViewController *root_view = [self.splitViewController.viewControllers objectAtIndex:0];
[root_view forceReload];
[root_view.countdown_table reloadData];

But that only point to the Navigation Controller,而不是其中的 View Controller。即使模式被关闭,RootViewController 的 viewWillAppear 也不会触发。

我怎样才能指向这个文件? 谢谢!

I ran into an issue similar to this earlier on the iPhone, but the same solution doesn't seem to apply to the iPad environment. My goal is to call my method forceReload, defined in my RootViewController, that will reload the countdown_table's data in the RootView from the DetailView once a modal is dismissed. forceReload works fine when called directly from the RootViewController, but I can't seem to point to point to the RootViewController from the DetailView.

I've tried using

RootViewController *root_view = [self.splitViewController.viewControllers objectAtIndex:0];
[root_view forceReload];
[root_view.countdown_table reloadData];

But that only points to the Navigation Controller, not the View Controller inside of it. Even when the modal is dismissed, RootViewController's viewWillAppear does not fire.

How can I point to this file?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2024-11-24 13:03:53

尝试使用通知,即将 RootViewController 注册为 DetailView 或任何视图可能发送的通知的观察者。

在 RootViewController 的 viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(forceReload) 
                                             name:@"reloadRequest" 
                                           object:nil];

viewDidUnload 或 dealloc:

[[NSNotificationCenter defaultCenter] removeObserver:self];

中,并在 DetailViewController 或模态视图中(你没有说它们是相同的),在关闭视图之前或恰好在需要 RootViewController 调用 forceReload 时将其放置:

NSNotification *notif = [NSNotification notificationWithName:@"reloadRequest" object:self];
[[NSNotificationCenter defaultCenter] postNotification:notif];

Try using notifications, i.e., register RootViewController as an observer for notifications that your DetailView or any view may send.

in RootViewController's viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(forceReload) 
                                             name:@"reloadRequest" 
                                           object:nil];

viewDidUnload or in dealloc:

[[NSNotificationCenter defaultCenter] removeObserver:self];

And in your DetailViewController or your modal view (you didn't say they're the same), put this right before you dismiss the view or exactly when you need RootViewController to call forceReload:

NSNotification *notif = [NSNotification notificationWithName:@"reloadRequest" object:self];
[[NSNotificationCenter defaultCenter] postNotification:notif];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文