嗨我有兩個代碼爲某人的原因1作品,而其他人不能有人請解釋爲什麼?第一個功能起作用,而第二個功能不起作用。我試圖生成一個單元格作爲類型PayNowCell,並將其後的每個單元格作爲CheckOutCell類型。但是,它只允許我將第一個單元格作爲CheckOutCell,第二個單元格作爲PayNowCell,將後面的每個單元格作爲CheckOutCell。謝謝!!!錯誤是索引超出界限。並且它指向這條線
cell.item = checkout [indexPath.item]。UICollectionView不斷崩潰,除非我設置indexpath.items = 1
基本上我有一個動態數組結賬[]和IM只是想插入名爲paynow說明電池ontop的每個checkoutcell的同時結帳[]增大和收縮
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == 1 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "paynow", for: indexPath) as! PayNowCell //init cells
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! CheckoutCell //init cells
cell.item = checkout[indexPath.item]
return cell
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "paynow", for: indexPath) as! PayNowCell //init cells
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! CheckoutCell //init cells
cell.item = checkout[indexPath.item]
return cell
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (checkout.count + 1) //init number of cells
}
請詳細解釋並在此處顯示您的numberOfItem行代碼。 –
添加了對此的抱歉 –