这看起来很荒谬,但我似乎无法解决它。我需要在 TableView 中插入一行以响应推送通知。实现应该很简单
- (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 并将其链接到 Storyboard中的刷新按钮,它就会起作用。我需要做一些特殊的事情才能以编程方式更新 UITableView 吗?
最佳答案
尝试向表发送reloadData
消息。这应该强制 TableView 更新。
关于objective-c - 从代码中在 UITableView 中插入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10149222/