Ich habe versucht, mein Swift-Programm auf Swift 3.1 zu bauen. Ich könnte es bauen. Allerdings kann es von Swift 3.1 nicht richtig funktionieren.UICollectionView Benutzerdefinierte Zelle
Ich habe den folgenden Fehler erhalten.
'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier SingleItemCell - must register a nib or a class for the identifier
Allerdings habe ich bereits SingleItemCell für uicollectionview registriert.
override func viewDidLoad() {
super.viewDidLoad()
//エリア情報の表示に必要なxibをcollectionviewに登録
var nib = UINib(nibName: "ItemCell", bundle:nil)
areaView.register(nib, forCellWithReuseIdentifier:"ItemCell")
nib = UINib(nibName: "SingleItemCell", bundle:nil)
areaView.register(nib, forCellWithReuseIdentifier:"SingleItemCell")
nib = UINib(nibName: "SftCollectionReusableView", bundle:nil)
areaView.register(nib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "SftCollectionReusableView")
areaView.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "EmptyView")
areaView.dataSource = dataSourcedelegate
areaView.delegate = dataSourcedelegate
....
}
/**
セル一つ一つの定義
- parameter collectionView: <#collectionView description#>
- parameter indexPath: <#indexPath description#>
- returns: <#return value description#>
*/
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
return configureCell(collectionView, cellForRowAtIndexPath: indexPath)
}
/**
各セルの表示
- parameter collectionView: <#collectionView description#>
- parameter indexPath: <#indexPath description#>
- returns: <#return value description#>
*/
func configureCell(_ collectionView: UICollectionView, cellForRowAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 0{
return areaItemCell(collectionView, indexPath: indexPath)
}else{
let cell:SingleItemCell = collectionView.dequeueReusableCell(withReuseIdentifier: "SingleItemCell", for: indexPath) as! SingleItemCell
cell.itemLabel.text = "現在地から検索"
cell.itemLabel.addImage("common_here_icon",font: UIFont.boldSystemFont(ofSize: 20),marginx: -5,intLabelMode: ImageLabelMode.left.hashValue)
return cell
}
}
Elementzelle ist geladen. Allerdings ist SingleItemCell nicht geladen. Warum wurde es nicht geladen, auch wenn ich mich registriere.
Was ist das Problem?