iOS Swift 5 UICollectionView NIB寄存器不工作,我正在使用XIB文件

iOS Swift 5 UICollectionView NIB寄存器不工作,我正在使用XIB文件,ios,swift,swift5,Ios,Swift,Swift5,我的UICollectionView: @IBOutlet weak var mediaProfileCollectionView: UICollectionView! 我在viewDidLoad()中添加了以下代码: 然后我用在: viewModelProfile.mediaProfileCollectionView .asObservable() .bind(到:mediaProfileCollectionView.rx.items(单元格标识符:“MediaProfileCollecti

我的UICollectionView:

@IBOutlet weak var mediaProfileCollectionView: UICollectionView!
我在viewDidLoad()中添加了以下代码:

然后我用在:

viewModelProfile.mediaProfileCollectionView
.asObservable()
.bind(到:mediaProfileCollectionView.rx.items(单元格标识符:“MediaProfileCollectionViewCell”,单元格类型:MediaProfileCollectionViewCell.self)){(行、数据、单元格)中的
cell.setMediaImage(来源:数据)
}.处置(由:处置人)
然后我得到错误消息:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在名为“MediaProfileCollectionView”的捆绑包:“NSBundle(loaded)”中加载NIB”


有人能帮我吗?

您很可能想为单元格而不是视图本身注册xib:

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

系统告诉你它找不到笔尖,你做了什么来修复这个问题?我不知道还能做什么:(,你能给我一个解决方案吗?找不到具有给定文件的xib。请检查该文件是否存在并已添加到项目中。你不应该注册单元xib而不是视图xib吗?xib中有多少视图。根据我的经验,当你为可重用单元创建xib时,你不能在那里有任何其他视图。如果你有任何远程请删除它们。@AlbinMrngStar这将是另一个错误。这显然是一个不正确的字符串。
mediaProfileCollectionView.register(
   UINib(nibName: "MediaProfileCollectionViewCell", bundle: nil), 
   forCellWithReuseIdentifier: "MediaProfileCollectionViewCell"
)