UIViewController添加子视图给我错误:无法识别的选择器

时间:2011-02-07 07:45:06

标签: iphone ios uiview uiviewcontroller

我收到以下错误,我不确定是什么导致它。

2011-02-06 23:38:12.580 SApp[9648:207] -[Record superview]: unrecognized selector sent to instance 0x5f2a350
2011-02-06 23:38:12.583 SApp[9648:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Record superview]: unrecognized selector sent to instance 0x5f2a350'

创建错误的步骤:

  • 我的自定义类正被添加到 app delegate的窗口。
  • 我的类是UIViewController的子类。
  • 在我的自定义类中,我添加了另一个子视图(Record) UIViewController的子类。 - 这个 是错误发生的时候。

导致错误的代码

[self.view addSubview:[self.tabBarControllers objectAtIndex:0]];

我将所有.h文件都包含在应有的位置,所以我不确定是什么导致这种情况。和想法?

1 个答案:

答案 0 :(得分:12)

您无法将UIViewController(记录)添加为另一个视图的子视图。而是将该视图控制器管理的视图添加为子视图。

UIViewController *recordController = [self.tabBarControllers objectAtIndex:0];

[self.view addSubview:recordController.view];