我的HomeHorizontalSpecialCell
繼承UICollectionViewCell,並有一個屬性是collectionView。並通過延遲加載懶加載一個uicollectionview導致應用程序崩潰時,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結構。 在數據源的方法,我出列,這些可重複使用的註冊細胞
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
}
力解開細胞造成應用程序崩潰時的CollectionView出列上一些大尺寸的iPhone電池,但規模不小。 我發現這樣的情況,首次在大尺寸iPhone上初始化HomeHorizontalSpecialCell
,但尺寸較小時需要將collectionView滾動至初始化該單元格實例。
爲什麼在大尺寸iPhone上加載此單元格時應用程序崩潰?
有人可以幫忙嗎?
請填寫詳細的錯誤信息。 –