ios - 如何在底部插入带有动画的 UITableViewCell?
问题描述
我已阅读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
在键盘顶部。
任何帮助将不胜感激。
解决方案
尝试这个。
目标 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];
});
输出
迅速
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)
}
推荐阅读
- java - 框架的应用
- c# - 从 C# 中的特定标题名称读取 csv 文件
- c# - NCalc Evaluate() 给出错误答案
- windows - 从 Windows 7 通过 USB 连接到 Orbbec Persee 时出现问题
- java - JavaFX - 如何在可编辑的 TableView 中检查用户输入
- crm - Odoo vs 自制 cakephp 开发
- javascript - 创建自定义搜索管道以动态过滤结果后,我仍然失败:解析错误:找不到管道“过滤器”
- c++ - 每个线程完成后停止 io_service
- mysql - Spring Boot BCryptPasswordEncoder 编码密码看起来不像 BCrypt
- python - 如何组合 Python 32 位和 64 位模块