滚动到集合视图上的最后一条消息无法正常工作

时间:2018-01-13 00:17:14

标签: ios swift uicollectionview

我有一个CollectionView,底部有一个包含文本字段和其他元素的输入附件视图。该应用程序的工作方式类似于消息传递应用程序:您编写内容然后发送它,此时消息将添加到集合视图中。

问题在于,通过我实施的代码,"自动滚动"当有一定数量的消息(集合视图中的项目)时,星星工作,16-18是在自动滚动星星工作之前需要添加的项目数量。这是我到目前为止实施的代码:

DispatchQueue.main.async {
    self.collectionView?.reloadData()
    self.inputTextField.text = ""

    if self.messages.count > 0 {
       let indexpath = IndexPath(item: self.messages.count - 1, section: 0)
       self.collectionView?.scrollToItem(at: indexpath, at: .bottom, animated: true)
    }
}

该代码位于textFieldShouldReturn方法中。

这是我在行中设置断点时得到的" self.collectionView?..." enter image description here

先谢谢你的帮助!!!

0 个答案:

没有答案