如何通过推送通知通过NSNotification获取表视图?通过通知更新Tableview
当我的应用程序收到通知时,通过应用程序委托的- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
方法和应用,目前已经在运行,我更新数据(通过核心数据存储)
查看警报弹出,一旦被驳回,我请
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateConversations" object:nil];
在表格视图控制器:
- (void)viewDidLoad {
//some setup code removed
_someData = [[GGGroups findAllSortedBy:@"lastUpdated" ascending:NO withPredicate:[NSPredicate predicateWithFormat:@"ANY users = %@", [GGUser currentUser]]] mutableCopy];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateData:) name:@"updateConversations" object:nil];
}
- (void)updateData:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
NSLog(@"Updated those conversations");
});
}
我曾尝试添加和移除吨他dispatch_async主队列块。
它总是到达updateData方法(我可以看到NSLog),tableview本身永远不会更新。
我在这里做错了什么?
更新
更多的代码的要求。
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [_someData count];
}
此外,每个表视图单元格都配置为_someData的索引。
appDelegate更新GGGroups的核心数据结构,所以tableview应该相应地更新,但这不会发生,因为我迄今为止未知的原因。
NSLog的发生,对不对? – Undo
你确定你在IB中正确链接了tableView吗? – Pei
显示如何填充表格。 –