[英]trouble dequeuing uicollectionview cells (swift 3)
我在uicollectionview中使多個單元出隊時遇到麻煩。 有人可以逐步解釋從注冊到出隊的過程。 我找不到任何有關在一個集合視圖中加載兩個或更多uicollectionview單元的在線信息。 同樣,這是基於coreadata中的變量在單個collectionview中加載不止一種類型的單元格。
這是我到目前為止所擁有的。
這是我注冊細胞的地方
collectionView?.register(ShareCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.register(ShareCellMedia.self, forCellWithReuseIdentifier: mediaCellId)
這是我在索引路徑處的單元格
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath :
IndexPath) -> UICollectionViewCell {
let friend = fetchedResultsController.object(at: indexPath) as! Friend
if (friend.lastMessage?.hasImage)! == true {
let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier: mediaCellId, for: indexPath) as!
ShareCellMedia
mediaCell.cell = friend.lastMessage
return mediaCell
}else{
let regularCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as!
ShareCell
regularCell.cell = friend.lastMessage
return regularCell
}
}
如果您正在使用原型靜態單元格,則無需注冊該單元格;或者,如果您正在使用帶有xib的單元格,則可以像這樣注冊
collectionView.register(UINib(nibName: "name here",bundle:nil), forCellWithReuseIdentifier: "identifier")
並檢查或打印您的標識符
您是否正在使用xibs創建單元格?
如果是這樣,那么您必須像這樣在viewdidload中注冊筆尖單元
UINib *cellNib = [UINib nibWithNibName:@"yourCellNib" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"TheNibCellIdentifier"];
另外,加載單元時,必須確保使用相應的ReuseIdentifier :
yourCellNib*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TheNibCellIdentifier" forIndexPath:indexPath];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.