Swift 找不到委托方法
我已经为UICollectionViewDelegateFlowLayout实现了此委托方法,但在尝试将单元格从队列中取出时,出现以下错误:Swift 找不到委托方法,swift,uicollectionview,uicollectionviewdelegate,Swift,Uicollectionview,Uicollectionviewdelegate,我已经为UICollectionViewDelegateFlowLayout实现了此委托方法,但在尝试将单元格从队列中取出时,出现以下错误: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 如果我尝试这样做,我也会得到这样的结果:let cell=collecti
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
如果我尝试这样做,我也会得到这样的结果:let cell=collectionView.cellForItem(at:indexPath)as!RQTTipCell
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TipCell", for: indexPath) as! RQTTipCell
let height = self.proxyView!.tipCollect.contentSize.height
let width = cell.bagRatio.multiplier / height
return CGSize(width: width, height: height)
}
此indexPath应该是正确的,但似乎不正确。如果检查错误含义,则表示您试图从数组中获取的项不可用
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
您正试图在索引1
处获取内容,但数组大小为[0..0]
现在为什么会这样?
- 简单的解释是,当您试图从
获取单元格时,该移动不可用。原因可能是该单元格尚未添加CollectionView
optional
cast
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TipCell", for: indexPath) as? RQTTipCell {
let height = self.proxyView!.tipCollect.contentSize.height
let width = cell.bagRatio.multiplier / height
return CGSize(width: width, height: height)
} else {
// default CGSzie
CGSize()
}
}
如果检查错误含义,则表示您试图从数组中获取的项不可用
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
您正试图在索引1
处获取内容,但数组大小为[0..0]
现在为什么会这样?
- 简单的解释是,当您试图从
获取单元格时,该移动不可用。原因可能是该单元格尚未添加CollectionView
optional
cast
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TipCell", for: indexPath) as? RQTTipCell {
let height = self.proxyView!.tipCollect.contentSize.height
let width = cell.bagRatio.multiplier / height
return CGSize(width: width, height: height)
} else {
// default CGSzie
CGSize()
}
}
为什么它会问一个看不见的细胞的大小?好问题。您能检查一下单元格标识符是否正确吗?它是正确的。“TipCell”用于注册单元格。您可以尝试将
cell=collectionView.cellForItem(位于:indexPath)注册为!RQTTipCell
?如果细胞壁指数路径的退出也失败,这将返回细胞。为什么它会询问一个不可见的细胞的大小?好问题。您能检查一下单元格标识符是否正确吗?它是正确的。“TipCell”用于注册单元格。您可以尝试将cell=collectionView.cellForItem(位于:indexPath)注册为!RQTTipCell
?如果细胞壁指数路径的退出也失败,这将返回细胞。