【发布时间】:2018-12-23 15:19:36
【问题描述】:
我已经搜索了与此问题相关的各种链接,但无法解决此问题,这就是我发布此问题的原因。我有一个collectionView。在一个特定的单元格中,我有许多视图,例如 UserProfileView、ProductView、CommentBoxView 等。在 CommentBoxView 中有一个 textView,用户可以在其中输入然后发表评论。发表评论后,我想滚动那个特定的单元格,用户从哪个单元格发布了评论。我知道我必须使用self.collectionView.scrollToItem(at:IndexPath(item: indexNumber, section: sectionNumber), at: .right, animated: false)
这是代码,
func customCell(_ cell: UICollectionViewCell, didPressButton: UIButton, indexPathRow: Int, commentPost: String, commentatorImage: UIImageView, commentatorName: UILabel, comments: UITextView) {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
self.collectionView.reloadData()
self.postComment(commentatorImage: commentatorImage, commentatorName: commentatorName, comments: comments) })
}
但我的问题是:
- 我必须在哪里编写此代码?在视图中确实出现了?或在 评论发帖功能哪里成功了?
-
如何将 indexNumber 和 sectionNumber 传递给
self.collectionView.scrollToItem(at:IndexPath(item: indexNumber, section:sectionNumber)
请任何人帮助我解决这个问题。谢谢
【问题讨论】:
-
你可以使用其他类来添加评论吗??
-
我正在使用添加评论的功能。调用 api 的地方。如有必要,我可以使用其他课程。
-
你在哪里调用你的帖子评论方法?从一个按钮的动作可能是什么?
-
我使用了自定义委托
-
你能显示那个代码吗?
标签: ios uicollectionview swift4 uicollectionviewcell uicollectionviewdelegate