首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >断言失败in -[UICollectionView UICollectionView

断言失败in -[UICollectionView UICollectionView
EN

Stack Overflow用户
提问于 2016-09-06 11:05:05
回答 1查看 1.7K关注 0票数 0

我正在创建一个表视图,并在自定义UItableviewCell中使用集合视图,我还创建了一个自定义集合视图单元格。在TableViewCell中设置了集合视图的所有基本功能之后,当运行该应用程序时,我得到了崩溃的原因:

由于未命名异常“NSInternalInconsistencyException”终止应用程序,原因是:“调用-dequeueReusableCellWithReuseIdentifier:forIndexPath:或is nil (>)未检索从-collectionView:cellForItemAtIndexPath返回的视图:( {length = 2,path =0-0})”

我试图寻找更多,但找不到任何方向

下面是我的代码片段: 1.在TableViewcell awakeFrom Nib中:

代码语言:javascript
复制
 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方法:

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-05 13:16:01

正如在文章中提到的那样,我在桌面xib文件中工作,并且尝试做我需要做的事情,但是一旦我改变了我的方法,我在故事板中创建了UITableView中的tableview单元,并更新了所有的插座,然后运行应用程序。该应用程序正在运行fine....all,集合视图单元格中的插座是通过引用静态变量动态创建的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39347504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档