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:
- Created a UITableView subclass named SWTableViewCell
- Added a call in viewDidLoad to register the cell with interface builder:
[self.tableView registerClass:[SWTableViewCell class] forCellReuseIdentifier:@"Cell"];
- In the storyboard on my tableview, set the prototype cell's Class to SWTableViewCell
- In the storyboard, set the cell reuse identifier to "Cell"
- Added some labels to the prototype cell on the storyboard
- Still in the storyboard, ctrl-dragged from the labels to the SWTableViewCell.h to create outlets
- In my
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?