2015-01-08 2 views
0

Я добавил представление коллекции в пользовательскую ячейку представления таблицы, и теперь я пытаюсь добавить внутри нее собственную коллекцию. Мне не повезло зарегистрировать nib и загрузить ячейку в cellForItemAtIndexPath.iOS Swift - пользовательский UICollectionViewCell в пользовательском UITableViewCell

Я получаю эту ошибку:

2015-01-08 17:51:23.760 puma[9018:533346] *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UICollectionView.m:3318 
2015-01-08 17:51:23.764 puma[9018:533346] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' 

соответствующий код:

class CustomTableViewCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate { 


    @IBOutlet weak var collectionView: UICollectionView! 

    required init(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return 5 
    } 

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 

     var cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as? CustomCollectionViewCell 

     if (cell == nil) { 
      let nib = NSBundle.mainBundle().loadNibNamed("CustomCollectionCell", owner: CustomCollectionViewCell.self, options: nil) as NSArray 
      cell = nib.objectAtIndex(0) as? CustomCollectionViewCell 
     } 

     // Configure the cell 
     return cell! 
    } 

} 

class CustomCollectionViewCell: UICollectionViewCell { 

    required init(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 


} 
+0

Прежде всего, я не вижу, где вы пытаетесь зарегистрировать перо (загружая перо не то же самое, как регистрация одного). Во-вторых, dequeueReusableCellWithReuseIdentifier: forIndexPath: гарантированно вернет ячейку, поэтому предложение if (cell == nil) никогда не будет выполнено. – rdelmar

+0

Хорошо, я не понимал, что существует разница между регистрацией и загрузкой. Как бы я зарегистрировал наконечник, чтобы загрузить его? – coniferous

+0

Я думаю, мы должны знать, почему вы кладете ячейку просмотра коллекции в ячейку представления таблицы. Это странная вещь. – Abizern

ответ

0

По какой-то причине это выскакивать тонну недавно. Добавьте следующий код в viewDidLoad на контроллере просмотра таблицы:

if let myTableView = self.tableView { 
    self.tableView!.registerNib(UINib(nibName: "NibName", bundle: nil), forCellReuseIdentifier: "Cell") 
} 
Смежные вопросы