iOS Swift 5 UICollectionView NIB регистр не работает, я использую файл XIB - PullRequest
0 голосов
/ 05 марта 2020

Мой UICollectionView:

@IBOutlet weak var mediaProfileCollectionView: UICollectionView!

я добавляю этот код в viewDidLoad ():

mediaProfileCollectionView.register(UINib(nibName: "MediaProfileCollectionView", bundle: nil), forCellWithReuseIdentifier: "MediaProfileCollectionViewCell")

, затем я использую в:

    viewModelProfile.mediaProfileCollectionView
        .asObservable()
        .bind(to: mediaProfileCollectionView.rx.items(cellIdentifier: "MediaProfileCollectionViewCell", cellType: MediaProfileCollectionViewCell.self)) { (row,data,cell) in
            cell.setMediaImage(from: data)
        }.disposed(by: disposeBag)

, а затем я получить сообщение об ошибке:

Завершение приложения из-за необработанного исключения «NSInternalInconsistencyException», причина: «Не удалось загрузить NIB в комплекте:« NSBundle (загружен) »с именем« MediaProfileCollectionView »

Может кто-нибудь мне помочь ..

1 Ответ

0 голосов
/ 05 марта 2020

Скорее всего, вы хотите зарегистрировать xib для ячейки, а не для самого представления:

mediaProfileCollectionView.register(
   UINib(nibName: "MediaProfileCollectionViewCell", bundle: nil), 
   forCellWithReuseIdentifier: "MediaProfileCollectionViewCell"
)
...