2017-09-26 80 views
0

下面的函數調用生成線程1:EXC_BREAKPOINT(code = 1,subcode = 0x189d35a80)。CollectionView在pushViewController上生成SIGABRT

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委託中,我得到數組[count]> 0,但它沒有在numberOfItems之後調用collectionView:cellForItemAt,並在SIGABRT之後崩潰。任何想法?

+0

發佈您的'UICollectionViewDelegate'和'UICollectionViewDataSource'方法的代碼。 – Glenn

+0

只有數據源被執行! numberOfItemsInSection和cellForItemAt:函數的CollectionView(_的CollectionView:UICollectionView,numberOfItemsInSection部的:int) - >內部{ 返回messages.count }讓消息= self.messages [indexPath.item] 開關message.messageType { 情況.chatContent: let cell = collectionView.dequeueReusableCell(withReuseIdentifier:「ChatCollectionCell」,for:indexPath)as! ChatCollectionViewCell cell.setupWithMessage(message) return cell – Tarun

回答

0

自私的我! :P 我能夠解決這個問題,因爲這被認爲是一個愚蠢的錯誤。我打電話showChatView:多次,因爲我做了一個ChatViewController對象,但我忘了把pushViewController放在任何檢查下。而這就是崩潰的原因。謝謝

相關問題