2

我是 iPhone 应用程序开发的新手。

运行项目时出现此错误

Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<AboutViewController 0x91cc1d0> setValue:forUndefinedKey:]:

当我尝试导航到另一个名为AboutViewController.

我这样rightBarButton定义

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStylePlain target:self :@selector(showAbout)];
self.navigationItem.rightBarButtonItem = anotherButton;

方法showAbout

- (void)showAbout{

    AboutViewController *abvController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];

    [self.navigationController pushViewController:abvController animated:YES];    
    [abvController release];
}

此外,当我尝试使用presentModelViewController而不是navigationController,编译器显示它已被弃用。

4

3 回答 3

1

我发现了问题,这是因为我在 AboutViewController 中使用了一个按钮,我没有声明该按钮的属性。

但是谁能告诉我如何使用 ModelViewController 转到 ios6 中的新视图,因为当我使用方法 presentModelViewController 时,它会显示警告说它已被弃用

于 2012-11-09T08:52:28.623 回答
0

我认为问题在于您的 AboutViewController,而不是在当前视图控制器中。

我猜你的 AboutViewController nib 类是 UIViewController 类而不是 AboutViewController 类,尝试将其更改为正确的类。单击您的 nib 文件,然后单击文件的所有者,然后在右侧部分中单击第三个选项卡。您应该在顶部看到类,将其更改为 AboutViewCtroller。

于 2012-11-09T08:34:14.730 回答
0

通常这些类型的错误是由于在 xib 中连接的插座的问题而发生的。 主要场景:

  1. 在 xib 中查看插座未连接
  2. 已从接口文件中删除已连接插座的属性

    presentModelViewController 在 iOS 6 中已弃用。相反,您可以使用它presentViewController:animated:completion:来呈现 modalViews。

presentViewController:动画:完成:

呈现一个视图控制器。

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

参数

viewControllerToPresent

The view controller being presented.

旗帜

Pass YES to animate the presentation; otherwise, pass NO.

完成

A completion handler or NULL.

讨论

在 iPhone 和 iPod touch 上,呈现的视图始终是全屏的。在 iPad 上,演示文稿取决于 modalPresentationStyle 属性中的值。

此方法将presentedViewController 属性设置为指定的视图控制器,调整该视图控制器的视图大小,然后将该视图添加到视图层次结构中。视图根据呈现的视图控制器的 modalTransitionStyle 属性中指定的过渡样式在屏幕上进行动画处理。

在呈现的视图控制器上调用 viewDidAppear: 方法之后调用完成处理程序。

可用性

Available in iOS 5.0 and later.

在 UIViewController.h 中声明

有关更多详细信息,请查看UIViewController 类

于 2012-11-09T11:54:40.350 回答