我已阅读 https://stackoverflow.com/questions/
并尝试这样做:
//UITableView
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 50;
//Update the full code for the "return" key action
- (void)inputViewDidTapReturn:(MyInputView *)inputView text:(NSString *)text{
NSLog(@"send text-----%@",text);
[self.messageManager sendMessageTo:self.sessionID message:text completion:^(BOOL success, Message *message) {
if (success) {
[self.dataArray addObject:message];
NSIndexPath * bottomIndexPath = [NSIndexPath indexPathForRow:self.dataArray.count-1 inSection:0];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[bottomIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
[self.tableView scrollToRowAtIndexPath:bottomIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
} else {
}
}];
}
但是结果没有正确显示:
它从屏幕底部开始滚动。
UITableView
和 UITableViewCell
都使用了自动布局,而且 UITableView
已经在键盘上了。
任何帮助将不胜感激。
最佳答案
试试这个。
objective-c
[self.dataArray addObject:message];
[self.tableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *bottomIndexPath = [NSIndexPath indexPathForRow:self.dataArray.count-1 inSection:0];
[self.tableView scrollToRowAtIndexPath:bottomIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
输出
swift
self.dataArray.add(messasge)
self.tableView.reloadData()
DispatchQueue.main.async {
let bottomIndexPath = IndexPath(row: self.dataArray.count-1, section: 0)
self.tableView.scrollToRow(at: bottomIndexPath, at: .bottom, animated: true)
}
关于ios - 如何在底部插入带有动画的 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52148205/