将行插入UITableView时的行为

时间:2014-07-10 08:01:52

标签: ios iphone objective-c uitableview

我正在制作聊天应用程序。当键盘出现时,我的UITableView和工具栏(带有文本字段和按钮)使用setFrame方法向上移动。

当我在输入消息时收到来自其他用户的消息时,会出现问题。当发生这种情况时(即在insertRowsAtIndexPaths到UITableView之后),我的UITableView和工具栏会“重置”到原来的位置。

这是系统引起的正常行为吗?我在代码中找不到任何可以执行此操作的内容。我希望工具栏保持可见,这样我仍然可以输入我的信息。

这是将convoItem(会话项)添加到我的数组和UITableView的代码:

- (void)insertConvoItem:(ConvoItem *)item
{
    [_convoItems addObject:item];

    // Update the table view
    NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:([self.convoItems count] - 1) inSection:0];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];

    // Scroll to the bottom so we focus on the latest message
    NSUInteger numberOfRows = [self.tableView numberOfRowsInSection:0];
    if (numberOfRows) {
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:(numberOfRows - 1) inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }
}

1 个答案:

答案 0 :(得分:1)

这很正常。接收新消息会将您的表格视图重置为其原始位置。