UICollectionViewCell无法注册笔尖?

问题描述:

所述的ViewController的结构是:UICollectionViewCell无法注册笔尖?

-ViewController

- TableView中(相同的故事板内 - 视图 - 控制)

--- TableViewCell(在不同的XIB文件)

--- - CollectionView(在TableViewCell 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迅速文件内容:

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的collectionViewCell的隔档里添加的CollectionView将不会出现和我有添加自定义的一个,我不能注册collectionViewCell的笔尖,任何想法?

+0

好像问题是与tableviewcell,检查的UITableViewCell笔尖,如果你不小心添加任何其他意见或作出确定它是UITableViewCell – Akhilrajtr

u需要注册的tableview细胞中的ViewController和的CollectionView细胞在表格单元格的awakefrom笔尖为follws

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

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

} 
+0

的子类,现在它的工作,:)谢谢你让我的日子 – Jack