从AppDelegate重新加载tableView

Luu*_*sen 7 iphone cocoa-touch reload uitableview

我有一个非常简单的问题,但我仍然在寻找可可的方法.我有一个在Xcode中创建的普通rootViewController应用程序.在AppDelegate中,我有一个更新数据库的功能.当Push-message在运行时进入(didReceiveRemoteNotification :)时,数据会更新.

但是我如何获得RootViewController的句柄,告诉它更新其对象然后重新加载表(这是一个函数)?

Wri*_*sCS 20

您可以使用NSNotificationCenter,请参阅NSNotificationCenter类参考

在你rootViewControllerviewDidLoad,添加以下内容:

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

并添加以下方法:

- (void)updateView:(NSNotification *)notification {
    [myTableView reloadData]; 
}
Run Code Online (Sandbox Code Playgroud)

在你AppDelegatedidReceiveRemoteNotification,添加以下内容:

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil];
Run Code Online (Sandbox Code Playgroud)