0
votes

My problem is I can't show inherited class from UITableViewController with static cells. I am using storyboard for easy custom cells setup (I want to get a Settings App like behavior) in UITableViewController. But I need to nest it in another UIViewController which shows custom top bar (like navigation bar panel). So when I load my UITableViewController with this structure:

#import <UIKit/UIKit.h>

@interface MyCoolTableVC : UITableViewController

@end

I get no issues, all custom cells which I set in storyboard builder are shown in proper way in grouped table view. But when I am using subclass from UITableViewController:

#import <UIKit/UIKit.h>
#import "MyCoolTableVCSubclass.h"
@interface MyCoolTableVC : MyCoolTableVCSubclass

@end

I get this result:

enter image description here

which shows wild appearance of tableView, without sections and custom cells. I load my controller with this code, if it helps:

UIViewController *vcToGo = nil;
UIStoryboard *storyBoard = [[UIStoryboard storyboardWithName:@"MyCoolStoryboard" bundle:nil] init];
vcToGo = [storyBoard instantiateViewControllerWithIdentifier:@"profileTable"];
[self.navigationController pushViewController:vcToGo animated:YES];
1

1 Answers

2
votes

To use static cells, the datasource of the table view has to be set to a UITableViewController subclass, and you must not implement the datasource methods yourself.

The base UITableViewController provides everything to the table view in its own implementation of cellForRowAtIndexPath etc, using what you have put in the storyboard. So if your datasource does not inherit from UITableViewController, it will not be able to populate the table.

(note - This is what I assume is happening based on my own experiments, the internals of UITableViewController are not available to me)