【发布时间】: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 之后崩溃,然后是上面的崩溃。有什么想法吗?
【问题讨论】:
-
发布您的
UICollectionViewDelegate和UICollectionViewDataSource方法的代码。 -
只实现了数据源! 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