从AppDelegate重新加载tableView

问题描述:

我有一个非常简单的问题,但我仍然找到我的方式围绕可可。 我有一个正常的rootViewController应用程序在Xcode中创建。在AppDelegate中,我有一个函数来更新数据库。当运行时发送推送消息(didReceiveRemoteNotification :)时,数据被更新。从AppDelegate重新加载tableView

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

您可以使用NSNotificationCenter,看到NSNotificationCenter Class Reference

在你rootViewControllerviewDidLoad,添加以下内容:

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

,并添加下面的方法:

- (void)updateView:(NSNotification *)notification { 
    [myTableView reloadData]; 
} 

在你AppDelegate“ s didReceiveRemoteNotification,请添加以下内容:

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil]; 
+0

那么值得一问,因为它比我尝试过的任何东西都简单得多,而且对于更多功能非常有用!太感谢了! – 2011-01-20 20:40:20