0
votes

I'm trying to subclass a UIViewController that has an embedded UITableView and is a UiTableViewDataSource and UITableViewDelegate.

The master class looks like this:

@interface PFUIViewControllerWithTable : PFUIViewController     <UITableViewDelegate,UITableViewDataSource, RKObjectLoaderDelegate> {
UITableView *_tableView;
NSArray *_data;
}
@property (nonatomic,retain) UITableView *tableView;
@property (nonatomic,retain) NSArray *data;
- (void)configureCell:(PFRewardsUITableViewCell*)cell atIndexPath:(NSIndexPath *)indexPath;

and the implementation contains methods for populating the table view from the self.data property.

In the subclass, the data is populated and [self.tableView refresh] is called

@interface MySubclass : PFUIViewControllerWithTable <UITableViewDataSource,     UITableViewDelegate> {

}
- (void)loadObjectsFromDataStore;
- (void)loadLiveData;
- (void)configureCell:(PFRewardsUITableViewCell*)cell atIndexPath:(NSIndexPath *)indexPath;

The UItableViewDataSource methods are never called in this configuration. The delegate and data source are set to the master class. The master class populates the tableview from the self.data property, which is modified by the subclass.

So, what is the way to subclass such a view?

2
why UITableViewController is not enough for you? - Denis
Why adding the protocols UITableViewDataSource and UITableViewDelegate to the definition of MySubClass - PFUIViewControllerWithTable promises those implementations already. - Till
Are you sure the delegate/datasource is set? Do you set them in viewDidLoad? in that case are you calling [super viewDidLoad] from the subclass? - jbat100
I don't know if it's a recopying error but it's [self.tableView reloadData] instead of [self.tableView refresh]. - Yannick Loriot
Denis: In this case I have several views that need to be a similar style with table views. There is a lot of custom setup and data handling that I don't want to copy-paste to each one. Till: I added the definitions after toying around with it not having them (assumed they were inherited). I will remove them again, as they shouldn't be needed (but it wasn't working without them either) jbat100: Maybe I didn't get this right. I set them in initWithNibName.... could be the problem right there! - Steve

2 Answers

0
votes

Make sure that you're properly setting your delegate and datasources.

This is a mistake:

PFUIViewControllerWithTable *controller = [[MySubclass alloc] init];
[controller.tableView setDelegate:controller];
[controller.tableView setDataSource:controller];

This should be ok:

PFUIViewControllerWithTable *controller = [[MySubclass alloc] init];
[controller.tableView setDelegate:(MySubclass*)controller];
[controller.tableView setDataSource:(MySubclass*)controller];

I belive there's where your problem lies.

0
votes

Use IBOulet for tableview

Now check in xib of your view controller that table view is binded and its delegate and datasource provided to file owner.

Now check array you are providing to tableview has content in it