[英]How do i get conversation to display at the bottom by default where recent messages are present when entering chat screen?
After tapping on a conversation, the chat screen will start at the top and then scroll all the way to the bottom.点击对话后,聊天屏幕将从顶部开始,然后一直滚动到底部。 How can i bypass starting at the top and the scrolling to immediately displaying the most recent message at the bottom.我如何绕过从顶部开始并滚动到立即在底部显示最新消息。 This line of code is the closest thing i have found to doing what i want这行代码是我发现做我想做的最接近的事情
messagesCollectionView.scrollToLastItem(animated: true)
This is how it's currently displaying and then it will scroll to the bottom when i enter into the conversation (notice date)这是它当前的显示方式,然后当我进入对话时它会滚动到底部(通知日期)
This is how i want it do display upon entering the conversation (notice date)这就是我希望它在进入对话时显示的方式(通知日期)
private func listenForMessages(id: String) {
Networking.shared.getComments(requestId: 15836, completionHandler: { [weak self] (result) in
switch result {
case .success(let comments):
guard !comments.isEmpty else {
return
}
self?.messages = comments
DispatchQueue.main.async {
self?.messagesCollectionView.reloadData()
self?.messagesCollectionView.scrollToLastItem()
}
case .failure(let error):
print("failed to get messages: \(error)")
}
})
}
You would probably just be able to say animated: false
in that line.您可能只能在该行中说animated: false
。
You've not posted what you're doing in scrollToLastItem
, you can try this though:你还没有在scrollToLastItem
中发布你在做什么,你可以试试这个:
let lastItemIndex = IndexPath(item: collectionArray.count - 1, section: 0)
self.collectionView.scrollToItem(at: lastItemIndex, at: .bottom, animated: false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.