objective-c - 从代码中在 UITableView 中插入行

标签 objective-c ios uitableview

这看起来很荒谬,但我似乎无法解决它。我需要在 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/

相关文章:

ios - 在主界面添加新的 xib 时出错

ios - UIView 绘制(_ 矩形 : CGRect) doesn't work with multithreading

ios - 如何限制 RMMapView 中的 map 边界和缩放级别

objective-c - presentModalViewController 未被释放

ios - 如何在不改变原始宽高比的情况下组合两个不同大小的 UIImages?

ios - iOS chrome 中白页的 FB 重定向问题

iphone - 如何使用 quartz 在pdf文档中搜索文本

ios - 像刷新一样重新加载 tableview View

ios - UISearchController UITableView didSelectRowAtIndexPath 在过滤后不起作用

iphone - UITableView onTouch 隐藏键盘