【问题标题】:When Using JSQMessagesViewController the UI does not appear使用 JSQMessagesViewController 时,UI 不会出现
【发布时间】:2016-08-24 23:03:14
【问题描述】:

我正在尝试实现 JSQMessagesViewController,我正在关注 Ray Wenderlich 教程 (https://www.raywenderlich.com/122148/firebase-tutorial-real-time-chat),但 UI 没有出现在我的视图控制器上,它只是空白。 这是我的 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
}    

聊天视图控制器

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 文件来猜测发生了什么。我们需要更多信息。
  • 您需要致电super.viewDidLoadsuper.viewDidAppear
  • 哇,很简单,谢谢
  • 您不需要BridgingHeader 来完成此操作。
  • 你的setupBubbles()函数在哪里

标签: ios jsqmessagesviewcontroller


【解决方案1】:

您必须致电super.viewDidLoad & super.viewDidDisappear

【讨论】:

    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 2016-12-21
    • 2018-06-06
    相关资源
    最近更新 更多