2017-04-19 179 views
0

我试图在Swift 3.1上构建我的swift程序。 我可以建立它。 但是它无法从Swift 3.1正常工作。UICollectionView自定义单元格

我得到了以下错误。

'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier SingleItemCell - must register a nib or a class for the identifier 

但是,我已经注册了SingleItemCell for uicollectionview。

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 
    } 
} 

Itemcell已加载。 但是,SingleItemCell未加载。 即使我注册,为什么它没有被加载。

这是什么问题?

回答

1

我可以自己解决。 我附加我的修复捕获。

enter image description here

我改变方法的调用顺序。 然后,我的系统正常工作。 我万阿英,蒋达清是

viewModel.areas.asObservable().bindTo(areaView.rx.items(dataSource: dataSourcedelegate)) 
     .addDisposableTo(disposeBag) 

上述方法获得注册自定义单元格之前被调用。