这似乎很荒谬,但我似乎无法解决。我需要在表视图中插入一行以响应推送通知。实现应尽可能简单

- (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吗?

最佳答案

尝试向表发送reloadData消息。这应强制更新表视图。

10-06 13:39