iPhone:“无法识别的选择器发送到实例”

发布于 2024-08-17 12:00:43 字数 1184 浏览 5 评论 0原文

我尝试根据 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 的状态将两个不同的视图设置到子视图中,但是当我尝试切换到表视图时总是收到以下错误:

2010-01-06 19:55:00.871 Handball [84675:40b] * -[UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 0x3b18360 2010-01-06 19:55:00.873 Handball[84675:40b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*** -[UIViewController tableView:numberOfRowsInSection:]:发送到无法识别的选择器实例 0x3b18360' 2010-01-06 19:55:00.874 手球[84675:40b] Stack:(

任何帮助都会非常非常感谢...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2024-08-24 12:00:43

虽然 tableV 被声明为 TableView,但它很可能使用简单的 UIViewConrtoller 进行初始化,如代码中所示。尝试将该行更改为:

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

TableView 应该是 UITableViewController 的子类型。

顺便说一句,同样的情况也可能发生在 GameView 上。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文