gpt4 book ai didi

ios - 使用 JSQMessagesViewController 时,UI 不会出现

转载 作者:行者123 更新时间:2023-11-29 00:42:30 25 4
gpt4 key购买 nike

我正在尝试实现 JSQMessagesViewController,并且我正在遵循 Ray Wenderlich 教程(https://www.raywenderlich.com/122148/firebase-tutorial-real-time-chat),但是 UI 没有出现在我的 View Controller 上,它只是空白。这是我的 pod 文件。

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

我尝试过使用桥接接头,但没有用,我一步步按照教程进行操作。

转到 ChatViewController

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
guard let editingVC = segue.destinationViewController as? ChatsViewController
else {
preconditionFailure("Bad")
}
editingVC.senderId = userID
editingVC.senderDisplayName = userName
}

聊天 View Controller

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
}

}

最佳答案

你必须调用super.viewDidLoad & super.viewDidDisappear

关于ios - 使用 JSQMessagesViewController 时,UI 不会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39112887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com