swalkner
swalkner

Reputation: 17329

iPhone: "unrecognized selector sent to instance"

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...

Upvotes: 1

Views: 6369

Answers (1)

notnoop
notnoop

Reputation: 59299

While tableV is declared to be a TableView, it's most likely initialized with a simple UIViewConrtoller, as it appears in your code. Try changing the line to:

TableView *tableV = [[TableView alloc] initWithNibName:@"TableView" bundle:nil];

And TableView should be a subtype of UITableViewController.

By the way, the same should probably happen with GameView as well.

Upvotes: 4

Related Questions