2017-04-19 176 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) 

上述方法獲得註冊自定義單元格之前被調用。