Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在一个CollectionView中加载多个nib文件?_Ios_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios 如何在一个CollectionView中加载多个nib文件?

Ios 如何在一个CollectionView中加载多个nib文件?,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,这仅加载DescriptionImageSliderCollectionViewCell。我很确定这里发生了什么,但我想同时加载这两个,但我不知道怎么做 注册集合视图单元格的我的代码: override func viewDidLoad() { super.viewDidLoad() let nibFile : UINib = UINib(nibName: "DescriptionNearCollectionViewCell", bundle: nil) descr

这仅加载
DescriptionImageSliderCollectionViewCell
。我很确定这里发生了什么,但我想同时加载这两个,但我不知道怎么做

注册集合视图单元格的我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    let nibFile : UINib =  UINib(nibName: "DescriptionNearCollectionViewCell", bundle: nil)

    descriptionCollectionView.register(nibFile, forCellWithReuseIdentifier: "descriptionCell")

    let nibFile2 : UINib =   UINib(nibName: "DescriptionImageSliderCollectionViewCell", bundle: nil)

    descriptionCollectionView.register(nibFile2, forCellWithReuseIdentifier: "descriptionCell")
    // Do any additional setup after loading the view.
}
退出可重用单元队列:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "descriptionCell", for: indexPath)
    return cell
}

不能使用同一个reuseIdentifier在CollectionView上注册多个nib。为以下各项使用唯一的一个:

override func viewDidLoad() {
    super.viewDidLoad()

    let nibFile : UINib =  UINib(nibName: "DescriptionNearCollectionViewCell", bundle: nil)

    descriptionCollectionView.register(nibFile, forCellWithReuseIdentifier: "descriptionCell")

    let nibFile2 : UINib =   UINib(nibName: "DescriptionImageSliderCollectionViewCell", bundle: nil)

    descriptionCollectionView.register(nibFile2, forCellWithReuseIdentifier: "descriptionCell2")
    // This >>                                                                               ^
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    if (youWantCellOne) {
        return collectionView.dequeueReusableCell(withReuseIdentifier: "descriptionCell", for: indexPath)
    } else {
        return collectionView.dequeueReusableCell(withReuseIdentifier: "descriptionCell2", for: indexPath)
    }
}

不能用同一个reuseIdentifier在CollectionView上注册多个nib。@brandonscript我可以用tableview吗?不能用你不需要的同一个reuseIdentifiert@brandonscript我应该为不同的重用标识符使用不同的nib文件吗?无论CollectionView或TableView如何为每个nib使用唯一的重用标识符,是的。正确的命名约定“descriptionCell2”或“descriptionCell2”是什么?如果你告诉我,我会很高兴的。感谢没有正确的命名约定;您可以自己制作并坚持(或不坚持)它会导致崩溃:“无法在捆绑包中加载NIB…”听起来您的捆绑包id不正确,但请打开一个新问题以获得正确答案。