2017-04-19 4 views
0

Swift 3.1에서 신속한 프로그램을 만들려고했습니다. 그것을 만들 수 있습니다. 그러나 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 

그러나 저는 이미 uicollectionview 용 SingleItemCell을 등록했습니다.

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

나는 방법의 호출 순서를 변경했습니다. 그러면 시스템이 제대로 작동합니다. 내 probelm는 방법 위의

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

는 등록 사용자 정의 셀을 얻기 전에 호출되는 것입니다.