gpt4 book ai didi

ios - UICollectionView 中的 IBOutlets 为 nil - Swift

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:11 24 4
gpt4 key购买 nike

当我打印我在 MyCell 类中声明的 IBOutlets 时,它们结果为零。

ViewController 中的方法

public override func viewDidLoad() {
super.viewDidLoad()
self.seriesCollectionView.register(MyCell.self, forCellWithReuseIdentifier: "MyCell")
}

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as! MyCell
cell.setup()

return cell
}

MyCell 类

class MTSeriesViewCell: UICollectionViewCell {
@IBOutlet weak var cellView: UIView!

@IBOutlet weak var cellImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
}

public func setup() {
print(cellView)
}

}

有没有其他方法可以在 ViewController 的 viewDidLoad 中初始化/注册 MyCell 类?

最佳答案

代替:

self.seriesCollectionView.register(MyCell.self, forCellWithReuseIdentifier: "MyCell")

使用:

self.seriesCollectionView.register(UINib(nibName: "MyCellXibName", bundle: nil), forCellWithReuseIdentifier: "MyCell")

关于ios - UICollectionView 中的 IBOutlets 为 nil - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43655113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com