这似乎很荒谬,但我似乎无法解决。我需要在表格视图中插入一行以响应推送通知。实现应该很简单
- (void)didSaveMessage:(Message*)message atIndex:(int)index
{
//check to make sure I have an array to populate the table from...
if (self.messageManager.messages != nil)
{
self.indexRow = index;
NSLog(@"refresh table view from code");
//remove a label that says "You have no messages"...
[[messageTable tableFooterView] removeFromSuperview];
[messageTable beginUpdates];
[messageTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]]
withRowAnimation:UITableViewRowAnimationFade];
[messageTable endUpdates];
[self scrollToNewestMessage];
}
}
当我收到远程通知并且它触发时调用此方法。日志语句打印。但是,UITableView 不会更新。对我来说特别奇怪的是,如果我将相同的代码放在 IBAction 中并将其链接到情节提要中的刷新按钮,它就可以工作。以编程方式更新 UITableView 是否需要做一些特别的事情?