iPhone: “unrecognized selector sent to instance”

拥有回忆 提交于 2019-12-20 04:23:56

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2015419/iphone-unrecognized-selector-sent-to-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!