【发布时间】:2019-12-10 22:51:52
【问题描述】:
当用户单击发送消息 UIButton 并且当用户再次打开应用程序时,我想从下到上滚动我的 UICollectionView,最后发送的消息必须首先在底部看到。
我刚刚尝试了所有堆栈溢出答案和其他网站代码,但找不到任何解决我的问题的方法。
import UIKit
import Kingfisher
import Firebase
import IQKeyboardManagerSwift
class FireStoreChatViewController: UIViewController, UITextViewDelegate,UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
{
@IBOutlet var collectionView: UICollectionView!
@IBOutlet weak var sendMessageBtn: UIButton!
var comeFrom : String = ""
var mChatUser : String = ""
var mChatUserName : String = ""
var mCurruntUserId : String = ""
var isFirstPageFirstLoad: Bool = false
var lastVisible: DocumentSnapshot? = nil
var messageList: [Messages] = []
override func viewDidLoad()
{
super.viewDidLoad()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
self.messageList.reverse()
return messageList.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
if messageList[indexPath.row].from == mCurruntUserId
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Message", for: indexPath as IndexPath) as! MessageCollectionViewCell
}
return cell
}
@IBAction func sendMessageAction(_ sender: UIButton)
{
sendMessage()
}
func getMessage(mChatUser: String, mCurruntUser: String)
{
// code
}
func sendMessage()
{
// code
}
func updateChatListData()
{
// code
}
}
输出
打开聊天应用模块时首先看到的第一个索引路径。
【问题讨论】:
-
你找到这个问题的解决方案了吗?
标签: ios swift uicollectionview swift4 uicollectionviewcell