Ios UICollectionViewCell无法注册nib?

Ios UICollectionViewCell无法注册nib?,ios,xcode,uitableview,collectionview,Ios,Xcode,Uitableview,Collectionview,viewcontroller的结构是: -视图控制器 --TableView(在同一故事板内-viewcontroller) ---TableViewCell(在不同的xib文件中) ----CollectionView(表内视图单元格xib) -----CollectionViewCell(在不同的Xib文件中) 我的问题是我总是会遇到这样的错误: 2017-07-14 13:49:36.752763+0300 muzeit[10370:3481928] *** Assertion failu

viewcontroller的结构是:

-视图控制器

--TableView(在同一故事板内-viewcontroller)

---TableViewCell(在不同的xib文件中)

----CollectionView(表内视图单元格xib)

-----CollectionViewCell(在不同的Xib文件中)

我的问题是我总是会遇到这样的错误:

2017-07-14 13:49:36.752763+0300 muzeit[10370:3481928] *** Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.8.1/UITableView.m:6696
2017-07-14 13:49:36.755821+0300 muzeit[10370:3481928] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (tbc_horizontal_songs) - nib must contain exactly one top level object which must be a UITableViewCell instance'
*** First throw call stack:
(0x188f0afe0 0x18796c538 0x188f0aeb4 0x1899a2720 0x18f179768 0x18f1b3cc8 0x100236478 0x100236630 0x18f3811f8 0x18f381410 0x18f36eb14 0x18f386400 0x18f11e858 0x18f03907c 0x18c229274 0x18c21dde8 0x18f04d814 0x18f173a50 0x18f1737f0 0x18f172a9c 0x18f172820 0x18f17267c 0x18f172350 0x10025c9c0 0x10025cb94 0x18f053bf4 0x18f053964 0x18f0f3458 0x18f0f2c2c 0x18f0f27e0 0x18f0f2744 0x18f03907c 0x18c229274 0x18c21dde8 0x18c21dca8 0x18c19934c 0x18c1c03ac 0x18c1c0e78 0x188eb89a8 0x188eb6630 0x188de6dc4 0x18f0a6384 0x18f0a1058 0x1001e97bc 0x187df559c)
libc++abi.dylib: terminating with uncaught exception of type NSException
TableViewCell swift文件内容:

class tbc_horizontal_songs: UITableViewCell {


    @IBOutlet weak var collectionView : UICollectionView!

    override func awakeFromNib() {
        super.awakeFromNib()

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
}


extension tbc_horizontal_songs : UICollectionViewDataSource {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 12
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cvc_song", for: indexPath as IndexPath) as! cvc_song
        return cell
    }
}

extension tbc_horizontal_songs : UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        let itemsPerRow:CGFloat = 4
        let hardCodedPadding:CGFloat = 5
        let itemWidth = (collectionView.bounds.width / itemsPerRow) - hardCodedPadding
        let itemHeight = collectionView.bounds.height - (2 * hardCodedPadding)
        return CGSize(width: itemWidth, height: itemHeight)

    }

}

因为当我在tableviewcell的单独文件中添加collectionview时,collectionViewCell将不会出现,而且我必须添加自定义的collectionViewCell,所以我无法注册collectionViewCell的nib,知道吗

u需要在viewcontroller中注册tableview单元格,并从表单元格的nib中在awakeView中注册collectionview单元格,如下所示

tableview.register(UINib(nibName: "nibname", bundle: nil), forCellWithReuseIdentifier: "identifier")

 override func awakeFromNib() {
    super.awakeFromNib()
    collectionView.register(UINib(nibName: "collectioncellnibname", bundle: nil), forCellWithReuseIdentifier: "cvc_song")

 }

问题似乎出在tableviewcell上,如果不小心添加了任何其他视图,请检查UITableViewCell nib,或者确保它是UITableViewCell的子类