我正在创建一个表视图,并在自定义UItableviewCell中使用集合视图,我还创建了一个自定义集合视图单元格。在TableViewCell中设置了集合视图的所有基本功能之后,当运行该应用程序时,我得到了崩溃的原因:
由于未命名异常“NSInternalInconsistencyException”终止应用程序,原因是:“调用-dequeueReusableCellWithReuseIdentifier:forIndexPath:或is nil (>)未检索从-collectionView:cellForItemAtIndexPath返回的视图:( {length = 2,path =0-0})”
我试图寻找更多,但找不到任何方向
下面是我的代码片段: 1.在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方法:
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);
}发布于 2016-10-05 13:16:01
正如在文章中提到的那样,我在桌面xib文件中工作,并且尝试做我需要做的事情,但是一旦我改变了我的方法,我在故事板中创建了UITableView中的tableview单元,并更新了所有的插座,然后运行应用程序。该应用程序正在运行fine....all,集合视图单元格中的插座是通过引用静态变量动态创建的。
https://stackoverflow.com/questions/39347504
复制相似问题