When I print the IBOutlets I declared in MyCell class, they come out to be nil.
Methods in 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
class MTSeriesViewCell: UICollectionViewCell {
@IBOutlet weak var cellView: UIView!
@IBOutlet weak var cellImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
}
public func setup() {
print(cellView)
}
}
Is there any other way I should be initializing/registering MyCell class in viewDidLoad of ViewController?
Instead of:
self.seriesCollectionView.register(MyCell.self, forCellWithReuseIdentifier: "MyCell")
use:
self.seriesCollectionView.register(UINib(nibName: "MyCellXibName", bundle: nil), forCellWithReuseIdentifier: "MyCell")
In the xib for your custom cell you need to control-drag from you views onto file's owner and connect them to their IBOutlets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With