作者:非机动车地了 | 来源:互联网 | 2023-02-05 14:34
当我打印我在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类?
1> 小智..:
代替:
self.seriesCollectionView.register(MyCell.self, forCellWithReuseIdentifier: "MyCell")
使用:
self.seriesCollectionView.register(UINib(nibName: "MyCellXibName", bundle: nil), forCellWithReuseIdentifier: "MyCell")