【问题标题】:CollectionView generating SIGABRT on pushViewControllerCollectionView 在 pushViewController 上生成 SIGABRT
【发布时间】:2017-09-26 01:03:20
【问题描述】:

下面的函数调用生成线程 1:EXC_BREAKPOINT (code=1, subcode=0x189d35a80)。

func showChatView(message: ChatMessage) {
        DispatchQueue.main.async {
            if self.chatViewController == nil  {
                let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                self.chatViewController = mainStoryboard.instantiateViewController(withIdentifier: "VAChatViewController") as? VAChatViewController
                self.chatViewController?.delegate = self;
            }
            self.chatViewController?.messages += [message]

            self.navigationController?.pushViewController(self.chatViewController!, animated: true, completion: {
                let buttonMessage = self.chatViewController?.messages.last
                let hasButtons = buttonMessage?.hasButtons
                if hasButtons! {
                    let vaButtonModel = ChatMessage(buttons: buttonMessage?.buttons)
                    self.chatViewController?.addNewMessage(vaButtonModel)
                }
            })
        }
    }

还有一件事——VAChatViewController 实现了collectionView 来显示传入的聊天事件,这是对字符串消息“xyz”的响应。在 collectionView 代表中,我得到了 array[count] > 0,但它没有在 numberOfItems 之后调用 collectionView: cellForItemAt 并且在 SIGABRT 之后崩溃,然后是上面的崩溃。有什么想法吗?

【问题讨论】:

  • 发布您的UICollectionViewDelegateUICollectionViewDataSource 方法的代码。
  • 只实现了数据源! numberOfItemsInSection 和 cellForItemAt: func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return messages.count } let message = self.messages[indexPath.item] switch message.messageType { case .chatContent: let cell = collectionView .dequeueReusableCell(withReuseIdentifier: "ChatCollectionCell", for: indexPath) as! ChatCollectionViewCell cell.setupWithMessage(message) 返回单元格

标签: ios swift3 uicollectionview uicollectionviewlayout


【解决方案1】:

愚蠢的错误。我多次调用 showChatView: 因为我创建了一个 ChatViewController 对象,但我忘记将 pushViewController 置于任何检查之下。而且,这就是崩溃的原因。谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多