我的代碼在獲取索引路徑中的單元格的行中發生了以下錯誤,我無法對其進行調試。在調用cellForItemAtIndexPath()時發生EXC_BAD_INSTRUCTION錯誤
螺紋:EXC_BAD_INSTRUCTION(代碼= EXC_1386_INVOP,子碼=爲0x0)
var cell = CollectionViewCell()
for row in 0...self.collectionNetList.count {
let indexpath = NSIndexPath.init(forRow: row, inSection: 0)
self.cell = collectionView?.cellForItemAtIndexPath(indexpath) as! CollectionViewCell
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ CRASHES HERE ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
cell.dlImage.image=UIImage(named: "ted") //Modify the custom pictures on the cell
}
然而,在該方法相同的指令按預期方式工作。
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.cell = collectionView.cellForItemAtIndexPath(indexPath)! as! CollectionViewCell
}
似乎沒有必要在裏面一個問題,此外,該格式似乎是非常差,目前還不清楚你要問什麼。 – Robba
你連接了cell.dlImage的IBOutlet嗎?並請正確地合成你的問題......因爲它不是100%可以理解的 –
cell.dlImage在自定義單元中 – user7357445