相关疑难解决方法(0)

为什么UICollectionViewCell的出口是零?

我在Interface Builder中创建了一个自定义UICollectionViewCell,将它绑定到类上,然后当我想使用并将字符串设置为字符串上的标签时,tha label的值为nil.

override func viewDidLoad() {
    super.viewDidLoad()

    // Register cell classes
    self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "ls")
}

override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {

    var cell: LeftMenuCollectionViewCell
    cell = collectionView.dequeueReusableCellWithReuseIdentifier("ls", forIndexPath: indexPath) as LeftMenuCollectionViewCell
    println(cell.label) // <- this is nil, why??
    cell.label.text = "asd"

    return cell
}
Run Code Online (Sandbox Code Playgroud)

和子类细胞:

class LeftMenuCollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
}
Run Code Online (Sandbox Code Playgroud)

interface-builder ios uicollectionviewcell swift ios8

139
推荐指数
5
解决办法
3万
查看次数