简体   繁体   English

滚动到UITableView底部时出现问题

[英]Issue while scrolling to UITableView bottom

I have a chat application ,where in when I press the send button the table gets reloaded with new row and I am calling scroll to bottom function to scroll to the newly added cell. 我有一个聊天应用程序,其中当我按下发送按钮时,表格将重新加载新行,并且我正在调用滚动到底部功能滚动到新添加的单元格。 The problem is that my textview text does not get emptied until the tableview scrolls to the bottom. 问题是,直到tableview滚动到底部,我的textview文本才会被清空。 Is there any other way to perform these actions so as to reduce the time delay? 还有其他方法可以执行这些操作以减少时间延迟吗?

Scroll to botton code: 滚动到botton代码:

self.tableView.reloadData()
let section: Int = numberOfSections(in: self.tableView) - 1
let item: Int = tableView(self.tableView, numberOfRowsInSection:section) - 1
let lastIndexPath = IndexPath(item: item, section: section)
self.tableView.scrollToRow(at: lastIndexPath, at: .bottom, animated: false)

When I remove the above code, the textview gets emptied instantly 当我删除上面的代码时,textview立即清空

The issue : 问题 :

在此处输入图片说明

Make sure that you call reloadData() on the main thread. 确保在主线程上调用reloadData()。 Doing it in a background thread will often cause graphical delays and may even crash the application. 在后台线程中执行此操作通常会导致图形延迟,甚至可能使应用程序崩溃。

Also, where do you empty the textview? 另外,您在哪里清空textview?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM