0
我想實現JSQMessagesViewController,並且我遵循Ray Wenderlich教程(https://www.raywenderlich.com/122148/firebase-tutorial-real-time-chat),但UI沒有出現在我的視圖控制器上,它只是空白。 這是我的pod文件。當使用JSQMessagesViewController UI不會出現
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target "Sell Goods" do
pod 'Firebase'
pod 'Firebase/Storage'
pod 'Firebase/Database'
pod 'Google/SignIn'
pod 'JSQMessagesViewController'
end
我已經嘗試使用橋頭,但沒有奏效,我一步一步跟着教程。
Segue公司以ChatViewController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
guard let editingVC = segue.destinationViewController as? ChatsViewController
else {
preconditionFailure("Bad")
}
editingVC.senderId = userID
editingVC.senderDisplayName = userName
}
ChatViewController
import Firebase
import JSQMessagesViewController
class ChatsViewController: JSQMessagesViewController {
var messages = [JSQMessage]()
var outgoingBubbleImageView: JSQMessagesBubbleImage!
var incomingBubbleImageView: JSQMessagesBubbleImage!
override func viewDidLoad() {
title = "ChatChat"
setupBubbles()
//collectionView!.collectionViewLayout.incomingAvatarViewSize = CGSizeZero
//collectionView!.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(animated: Bool) {
resetScreen = true
}
private func setupBubbles() {
let factory = JSQMessagesBubbleImageFactory()
outgoingBubbleImageView = factory.outgoingMessagesBubbleImageWithColor(
UIColor.jsq_messageBubbleBlueColor())
incomingBubbleImageView = factory.incomingMessagesBubbleImageWithColor(
UIColor.jsq_messageBubbleLightGrayColor())
}
override func collectionView(collectionView: JSQMessagesCollectionView!,
messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! {
let message = messages[indexPath.item]
if message.senderId == senderId {
return outgoingBubbleImageView
} else {
return incomingBubbleImageView
}
}
override func collectionView(collectionView: JSQMessagesCollectionView!,
messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {
return messages[indexPath.item]
}
override func collectionView(collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return messages.count
}
override func collectionView(collectionView: JSQMessagesCollectionView!,
avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! {
return nil
}
}
我們不能猜測是什麼只向我們展示您的POD文件回事。我們需要更多信息。 – Brandon
編輯帖子。 –
你需要調用'super.viewDidLoad'和'super.viewDidAppear' – Brandon