问题描述
根据SegmentSwitcher的状态,我尝试将两个不同的视图设置为一个子视图:
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扩展了TableViewController,但是当我尝试切换到tableview时,总是出现以下错误:
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手球[84675:40b] *-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x3b183602010-01-06 19:55:00.873手球[84675:40b] * 由于未捕获的异常'NSInvalidArgumentException'终止了应用程序,原因:'***-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送至实例0x3b18360'2010-01-06 19:55:00.874手球[84675:40b]堆栈:(
2010-01-06 19:55:00.871 Handball[84675:40b] * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b183602010-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...
推荐答案
虽然声明tableV
为TableView
,但很可能使用简单的UIViewConrtoller
对其进行了初始化,因为它出现在代码中.尝试将行更改为:
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];
TableView
应该是UITableViewController
的子类型.
顺便说一句,GameView
也可能会发生同样的情况.
By the way, the same should probably happen with GameView
as well.
这篇关于iPhone:“无法识别的选择器已发送到实例"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!