【发布时间】:2017-07-03 21:19:10
【问题描述】:
我正在使用 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])
出现错误(对成员 'collectionView(_:numberOfItemsInSection:)' 的不明确引用
如何解决这个问题。并且正在使用故事板来影响 collectionView 的工作,因为我无法使用以下方法更改单元格大小:
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))
}
我只有一个断点,还没有达到!
【问题讨论】:
-
错误是指
numberOfItemsInSection。这个错误是否显示在行上?您对该功能的实现是什么样的?你为什么显示sizeForItemAt? -
你应该把它插入到
msg.count
标签: ios swift3 storyboard xcode8