my HomeHorizontalSpecialCell
UICollectionViewCellを継承し、collectionViewというプロパティを持ちます。データを設定すると、これはcollectionViewは、遅延ロードによってコレクションビューが遅くなると、コレクションビューが再利用可能なセルをデキューしたときにアプリケーションクラッシュが発生する
private lazy var _collectionView: UICollectionView! = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 10
let itemWidth = (kScreenWidth - 4 * layout.minimumLineSpacing)/3.4
let itemHeight = itemWidth
layout.itemSize = CGSize(width: itemWidth, height: itemHeight)
let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: itemHeight), collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = UIColor.white
collectionView.contentInset = UIEdgeInsetsMake(0, 7, 0, 7)
// register cell
collectionView.register(HomeHorizontalSpecialGoodCell.self, forCellWithReuseIdentifier: HomeHorizontalSpecialCell.reuseSpecialCellID)
collectionView.showsHorizontalScrollIndicator = false
self.contentView.addSubview(collectionView)
return collectionView
}()
を構築し、このcollectionViewはreloadData
メソッドの呼び出しや、細胞を構築し、登録を開始します。データソースの方法で は、私はcollectionViewは、いくつかの大きなサイズのiPhoneでセルをデキューが、小さなサイズでない場合、細胞原因アプリケーションのクラッシュをアンラップするために、これらの登録、再利用可能な細胞
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// crash at here on big size iPhone
let specialGoodCell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeHorizontalSpecialCell.reuseSpecialCellID, for: indexPath) as! HomeHorizontalSpecialGoodCell
if indexPath.row != (_dataList?._item.count)! { // good cells
specialGoodCell.goodModel = _dataList?._item[indexPath.row]
} else { // last cell
specialGoodCell.setMoreImage("spe_more")
}
return specialGoodCell
}
力をデキュー。 初めて大きなサイズのiPhoneで初めてHomeHorizontalSpecialCell
という初期の状況が見つかりましたが、小さなサイズでは、このセルインスタンスを初期化するためにcollectionViewをスクロールする必要があります。
大きなサイズのiPhoneでこのセルを読み込むと、アプリがクラッシュするのはなぜですか?
誰かが助けることができますか?
詳細なエラーメッセージを入力してください。 –