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")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments