I have a UITableView as a subview in a UIViewController. I'm not using UITableViewController because I have some other content that is not tableview-related taking up part of the screen. I am using storyboards. I have the tableview set up as an outlet, with the viewcontroller being the datasource and delegate. If I use the standard UITableViewCell in this scenario, everything works well and I can load content.
I need to use a custom UITableViewCell for this tableview, so I performed the following steps:
[self.tableView registerClass:[SWTableViewCell class] forCellReuseIdentifier:@"Cell"];cellForRowAtIndexPath: method, dequeue and cast the cell to the custom subclass: SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];The cell variable is the proper type when I check it. It's not a UITableViewCell, but a SWTableViewCell. But none of the outlets are populated. The properties exist, but they are nil. I'm sure there's a connection I must be missing, but i can't think of anything I skipped at this point.
Is this scenario possible, or does it just not work via IB and storyboards?
Removing the call to
[self.tableView registerClass:[SWTableViewCell class] forCellReuseIdentifier:@"Cell"];
solves the issue.
I don't know exactly what this method does as I've never used it, so I'll look into it. If anyone has information on wether or not this call is required for something, please tell us !
Edit :
So, the idea behind registerClass:forCellReuseIdentifier: is that it tells the tableView how to create new cells. That way, if dequeueReusableCellWithIdentifier: does not return a cell (if the queue is empty), the tableView knows how to create a new cell, and you don't need to manually create one).
Edit 2 :
I found this thread, in which it says :
If the cell is created using prototypes within a storyboard it is not necessary to register the class.
Simply calling dequeueReusableCellWithReuseIdentifier: will "activate" the cell reusing functionality of your tableView.
So registerClass:forCellReuseIdentifier: is to be called only if you manually build your cells, without the use of storyboards.
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