2016-09-06 123 views
-1

我正在创建一个表视图和自定义UItableviewCell内我正在使用集合视图,我也创建一个自定义collectionview单元格。设定TableViewCell集合视图中的所有基本功能后,当我跑了有理性崩溃的应用程序:声明失败 - [UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:]

终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,理由是:“认为从-collectionView返回:cellForItemAtIndexPath :({长度= 2,路径= 0 - 0})没有通过调用-dequeueReusableCellWithReuseIdentifier检索到:forIndexPath:或为nil(>)”

我试图寻找更多的钱,但无法找到任何方向

这是我的代码片段: 1.在TableViewcell awakeFrom笔尖:

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方法:

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); 
} 
+0

删除此行:'cell = NSBundle.mainBundle()。loadNibNamed(simpleTableIdentifier,owner:self,options:nil)[0] as! (MediaCollectionCell)' – sage444

+0

感谢您的评论,但我使用自定义收集单元格....现在我删除了该行....这次没有崩溃,但没有数据显示在单元格中,没有单元格显示.....你能否建议我另一种方法....? –

+0

对于这次崩溃,我改变了tableCell和collectionCell。我删除了两个单元格的xib,并将这些单元格添加到故事板tableView中。之后,它工作正常 –

回答

2

正如在文章中提到,我在厦门国际银行TableCell的文件工作,尽量做到为我所需要的,但有一次我改变我的方法,我创建tableview单元格到故事板内的UITableView,并更新所有插座,然后运行应用程序。该应用程序工作正常....集合视图单元格中的所有插座都是通过从其静态变量中引用来动态创建的。

+0

我也被困在相同的场景....现在罚款... –