如何通過推送通知通過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
顯示如何填充表格。 –