当我添加多条测试消息时,屏幕上只显示了两条。其他消息显然在那里,因为我可以复制它们,但颜色根本没有显示。当我滚动时,会出现一个新的两个文本,但它仍然只有两个。下面展示一些例子。
第一个屏幕截图显示屏幕首次加载的时间。当我移动它时,第二个显示。第三显示其他消息确实存在但不可见。有想法该怎么解决这个吗?另外,如何让名字出现?是否有在 Swift 中执行此操作的好指南?
这是我使用的代码:
var messages = [JSQMessage]()
var incomingBubbleImageView = JSQMessagesBubbleImageFactory.incomingMessageBubbleImageViewWithColor(UIColor.jsq_messageBubbleLightGrayColor())
var outgoingBubbleImageView = JSQMessagesBubbleImageFactory.outgoingMessageBubbleImageViewWithColor(UIColor.jsq_messageBubbleGreenColor())
override func viewDidLoad() {
super.viewDidLoad()
self.sender = UIDevice.currentDevice().identifierForVendor?.UUIDString
messages += [JSQMessage(text: "hello", sender: self.sender)]
messages += [JSQMessage(text: "hello", sender: "other")]
messages += [JSQMessage(text: "hello", sender: self.sender)]
messages += [JSQMessage(text: "hello", sender: "other")]
messages += [JSQMessage(text: "hello", sender: self.sender)]
messages += [JSQMessage(text: "hello", sender: "other")]
reloadMessagesView()
}
func reloadMessagesView() {
self.collectionView?.reloadData()
}
这是委托方法的扩展代码:
extension TestJSQ {
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(self.messages.count)
return self.messages.count
}
override func collectionView(collectionView: JSQMessagesCollectionView!, messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {
let data = self.messages[indexPath.row]
return data
}
// 覆盖 func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!) { // self.messages.removeAtIndex(indexPath.row)
override func collectionView(collectionView: JSQMessagesCollectionView, bubbleImageViewForItemAtIndexPath indexPath: NSIndexPath) -> UIImageView {
let data = messages[indexPath.row]
switch(data.sender) {
case self.sender:
return self.outgoingBubbleImageView
default:
return self.incomingBubbleImageView
}
}
override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageViewForItemAtIndexPath indexPath: NSIndexPath!) -> UIImageView! {
return nil
}
}
任何帮助将非常感激!!!