I try to set two different views into a subview, according to the state of a SegmentSwitcher:
if ([sender selectedSegmentIndex] == gameIndex) {
if (self.gameView.view == nil) {
GameView *gameV = [[UIViewController alloc] initWithNibName:@"GameView" bundle:nil];
self.gameView = gameV;
[gameV release];
}
[tableView.view removeFromSuperview];
[subView insertSubview:gameView.view atIndex:0];
} else {
if (self.tableView.view == nil) {
TableView *tableV = [[UIViewController alloc] initWithNibName:@"TableView" bundle:nil];
self.tableView = tableV;
[tableV release];
}
[tableView.view removeFromSuperview];
[subView insertSubview:tableView.view atIndex:0];
}
TableView extends TableViewController, but I always get the following error when I try to switch to the tableview:
2010-01-06 19:55:00.871 Handball[84675:40b] * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b18360
2010-01-06 19:55:00.873 Handball[84675:40b] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b18360’
2010-01-06 19:55:00.874 Handball[84675:40b] Stack: (
Any help would be REALLY, REALLY appreciated…
While
tableVis declared to be aTableView, it’s most likely initialized with a simpleUIViewConrtoller, as it appears in your code. Try changing the line to:And
TableViewshould be a subtype ofUITableViewController.By the way, the same should probably happen with
GameViewas well.