In viewDidLoad I have:
[self.tableView registerNib:[UINib nibWithNibName:@"TypeOneCell" bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:@"CustomCellOne"];
and cellForRowAtIndexPath:
TypeOneCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellOne"];
return cell;
I want to use the same UITableViewController class for all the tables I push/pop. So I’ll probably create an enumerated type and a variable for it. So then I’d check which type the view controller is and then make my adjustments accordingly. My question is how I would go about doing this in the same way as above. Is it a matter of (viewDidLoad):
switch (self.theControllerType) {
case CPTypeOne:
[self.tableView registerNib:[UINib nibWithNibName:@"TypeOneCell" bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:@"CustomCellOne"];
break;
case CPTypeTwo:
[self.tableView registerNib:[UINib nibWithNibName:@"TypeTwoCell" bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:@"CustomCellTwo"];
break;
default:
break;
}
and then (cellForRowAtIndexPath):
switch (self.theControllerType) {
case CPTypeOne {
TypeOneCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellOne"];
return cell;
break;
case CPTypeTwo {
TypeOneCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellTwo"];
return cell;
break;
default:
break;
}
Or is this the wrong approach? Is there a more efficient way of doing this?
Remove the switch condition in the
viewDidLoadmethod and everything will work fine.