Assertion failure in -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:]

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

I am creating a table view and inside a custom UItableviewCell I am using collection view and I also create a custom collectionview cell. After setting all the basic functionalities of collection view in TableViewCell, When run the app I got the crash with reason:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:cellForItemAtIndexPath: ( {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableCellWithReuseIdentifier:forIndexPath: or is nil (>)'

I tried to search more for it but can't find any direction

Here is my code snippet: 1. In TableViewcell awakeFrom Nib:

 override func awakeFromNib() {     super.awakeFromNib()     //  self.collectionView_Files.registerNib(UINib(nibName: "MediaCollectionCell", bundle: nil), forCellWithReuseIdentifier: "MediaCollectionCell")    self.collectionView_Files.registerClass(MediaCollectionCell.self, forCellWithReuseIdentifier: "MediaCollectionCell") } 

CollectionView methods:

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {      return arrFolderData.count }  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {       let simpleTableIdentifier = "MediaCollectionCell"         var cell: MediaCollectionCell = collectionView.dequeueReusableCellWithReuseIdentifier(simpleTableIdentifier, forIndexPath: indexPath) as! MediaCollectionCell     cell = NSBundle.mainBundle().loadNibNamed(simpleTableIdentifier, owner: self, options: nil)[0] as! (MediaCollectionCell)      let dict = arrFolderData[indexPath.row]      if(dict["file_type"] as! String == "0") { /// Means image     cell.imgView_Item.image = UIImage(named: "images_41")         cell.btn_ViewImage.hidden = false         cell.btn_PlayVideo.hidden = true     } else if (dict["file_type"] as! String == "1") { /// Means video         cell.btn_ViewImage.hidden = true         cell.btn_PlayVideo.hidden = false         cell.imgView_Item.image = UIImage(named: "video_thumb_icon")     }      //   cell.backgroundColor = arrFolderData[indexPath.item]      return cell }  func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {     print("Collection view at row \(collectionView.tag) selected index path \(indexPath)") }  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {       let length = (UIScreen.mainScreen().bounds.width-15)/2     return CGSizeMake(length,length); } 

回答1:

As mentioned in the post, I was working in tablecell xib file and try to do as I need, however once I change my approach and I create tableview cell into the UITableView inside the storyboard and update all the outlets and then run the app. The app was working fine....all the outlets in collection view cell are dynamically created with taking reference from their static variables.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!