从DetailView在MasterView中重新加载数据 [英] reloadData in MasterView from DetailView

查看:143
本文介绍了从DetailView在MasterView中重新加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我尝试过使用

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

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

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!

推荐答案

尝试使用通知,即注册RootViewController作为您的DetailView或任何视图的通知的观察者可以在RootViewController的viewDidLoad中发送。

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

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

viewDidUnload或dealloc:

viewDidUnload or in dealloc:

[[NSNotificationCenter defaultCenter] removeObserver:self];

在你的DetailViewController或你的模态视图中(你没有说它们是相同的),在您解除视图之前或在您需要RootViewController调用forceReload时确切地说:

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

这篇关于从DetailView在MasterView中重新加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆