Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awakeFromNib is not getting called in Custom cell class due to which IBOutlets are nil

I am new to iOS programming.I have created a customcell class and awakefromnib method is not getting called because of this the IBOutlets are comings as nil! It is driving me crazy! Please help! I am using storyboards not xibs.

like image 570
iBuilt Avatar asked Jan 08 '16 06:01

iBuilt


2 Answers

I also ran into this issue and the problem was I was calling:

self.collectionView.register(CollectionCell.self, forCellWithReuseIdentifier: "CollectionCell")

even though I had actually added the collection view cell in the storyboard. If that's the case then registering the class is unnecessary and causes all your IBOutlets to be nil when the cell is dequeued

like image 190
Nick Kirsten Avatar answered Sep 28 '22 05:09

Nick Kirsten


I recently ran into this issue and it was due to incorrectly registering the cell. To have the UITableViewCell loaded from a nib you need to register like this:

override func viewDidLoad() {
    super.viewDidLoad()

    // .....

    let cellNib = UINib(nibName: "YourCellNibName", bundle: nil)
    tableView.register(cellNib, forCellReuseIdentifier: "YourCellIdentifier")
}
like image 30
Rick Avatar answered Sep 28 '22 05:09

Rick