该标签似乎返回nil,即使我已正确设置了redirectIdentifier和标签。

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    var identifier: String = "CollectionCell"
    var cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as! UICollectionViewCell

    // Configure the cell


    //save till later, when images are actually present

    //var cellItem1 = hostManager[indexPath.row * 2]

    let label:UILabel = cell.viewWithTag(1) as! UILabel
    return cell

}

程序在将标签设置为viewWithTag的位置中断。我没有为单元设置自定义类,只有原型。标签设置在情节提要上。收到错误“EXC_BAD_INSTRUCTION ...”。任何帮助将不胜感激,谢谢!

最佳答案

尝试从viewDidLoad中删除此行:

self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

关于ios - UICollectionView cell.ViewWithTag为UILabel返回nil,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31781933/

10-12 03:43
查看更多