xcode 4 - 链接以查看选项卡控制器中的导航控制器

时间:2011-12-12 21:57:12

标签: xcode uiviewcontroller

我有一个标签栏,其中包含一个导航控制器。使用此导航控制器,我打开一个新站点。这个新网站包含应该打开其他网站的按钮。但是当我点击这些按钮时会出现错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController buttonPushTestList:]: unrecognized selector sent to instance 0x4eac880'

在标签控制器中打开带有导航控制器的站点包含以下代码:

.h文件:

- (IBAction) buttonPushTestList:(id)sender;

.m文件:

- (IBAction)buttonPushTestList:(id)sender {

UIViewController *testlist = [[UIViewController alloc] initWithNibName: @"TestList" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController: testlist animated:YES];

}

我做错了什么? :(

1 个答案:

答案 0 :(得分:2)

您正在使用UIViewController的实例。您应该使用UIViewController的子类的实例。

你有一些类,我怀疑它是UIViewController的子类。在该类中,您已定义方法buttonPushListTest:。您没有告诉我们该类的名称,因此我将其称为JasminViewController。

我假设您有一个带按钮的笔尖,并且您已配置该按钮以将buttonPushListTest:消息发送到目标。 nib认为目标的类是JasminViewController。

但是,在运行时,按钮的目标是而不是 JasminViewController。在运行时,目标是一个普通的旧UIViewController。您可以告诉,因为错误消息显示为UIViewController。

因此,您的程序中有一个位置,您创建的对象是按钮的目标。您应该创建一个JasinViewController作为目标,而是创建一个普通的旧UIViewController。