[英]Behavior when inserting a row to a UITableView
我正在做一个聊天应用程序。 当键盘出现时,我的UITableView和工具栏(带有文本字段和按钮)使用setFrame
方法向上移动。
当我在键入消息时收到来自其他用户的消息时,会发生问题。 当发生这种情况时(即, insertRowsAtIndexPaths
向UITableView insertRowsAtIndexPaths
之后),我的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];
}
}
这是正常的。 接收新消息会将您的表格视图重置为其原始位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.