我正在用Swift 3在Xcode 8中创建一个聊天应用程序,并使用collectionView查看消息。但是,当按“发送”时,我遇到了在“收藏”视图中插入新项目的问题:
msg.append(message) // msg : Messages Array
let item = msg.count - 1
let IndexPath = NSIndexPath(item: item, section: 0)
self.collectionView.insertItems(at: [IndexPath])
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let messageText = msg[indexPath.item].text {
let size = CGSize(width: 250 , height: 1000)
let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
let esf = NSString(string: messageText).boundingRect(with: size, options: options, attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: CGFloat(18))], context: nil)
print("Changed")
return CGSize(dictionaryRepresentation: esf as! CFDictionary)!
}
print("Not Changed")
return CGSize(width: view.frame.width, height: CGFloat(100))
}
我只有一个转折点,还没有达到!