从DetailView在MasterView中重新加载数据

drf*_*ks3 0 objective-c reloaddata ios4 xcode4

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

我试过用了

RootViewController *root_view = [self.splitViewController.viewControllers objectAtIndex:0];
[root_view forceReload];
[root_view.countdown_table reloadData];
Run Code Online (Sandbox Code Playgroud)

但这仅指向导航控制器,而不是其中的视图控制器.即使模态被解除,RootViewController的viewWillAppear也不会被触发.

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

小智 7

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

在RootViewController的viewDidLoad中:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(forceReload) 
                                             name:@"reloadRequest" 
                                           object:nil];
Run Code Online (Sandbox Code Playgroud)

viewDidUnload或dealloc:

[[NSNotificationCenter defaultCenter] removeObserver:self];
Run Code Online (Sandbox Code Playgroud)

在你的DetailViewController或你的模态视图中(你没有说它们是相同的),在解除视图之前或者当你需要RootViewController来调用forceReload时,把它放在正确的位置:

NSNotification *notif = [NSNotification notificationWithName:@"reloadRequest" object:self];
[[NSNotificationCenter defaultCenter] postNotification:notif];
Run Code Online (Sandbox Code Playgroud)