我有一个非常简单的问题,但我仍在寻找可可的方法。
我有一个在 Xcode 中创建的普通 rootViewController 应用程序。在 AppDelegate 中,我有一个更新数据库的函数。当运行时收到推送消息时 (didReceiveRemoteNotification:),数据就会更新。
但是我如何获得 RootViewController 的句柄,告诉它更新其对象,然后重新加载表(这是一个函数)?
您可以使用NSNotificationCenter
, see NSNotificationCenter 类参考 http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html
In your rootViewController
's viewDidLoad
,添加以下内容:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"updateRoot" object:nil];
并添加以下方法:
- (void)updateView:(NSNotification *)notification {
[myTableView reloadData];
}
In your AppDelegate
's didReceiveRemoteNotification
,添加以下内容:
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)