0

我用 ARC 创建了一个 tabBar 应用程序。所以默认设置会自动提供 2 个 viewController;

1) FirstViewController.h,FirstViewController.m;FirstViewController_iPhone.xib, FirstViewController_iPad.xib

2) SecondViewController.h、SecondViewController.m、SecondViewController_iPhone.xib、SecondViewController_iPad.xib

我想创建一个新的视图控制器“ViewController3”,但在文件创建过程中,我只能选择为 iPad 或 iPhone 创建(复选框“针对 iPad”)。我需要 iPhone 和 iPad xib,就像为我创建的 FirstViewController 和 SecondViewControllers 一样。所以我决定手动创建 xib 并继续在没有 xibs 的情况下创建文件。

所以很自然地在那之后我继续手动创建 2 个新闻 xib;ThirdViewController_iPhone.xib 和 ThirdViewController_iPad.xib

我将此行添加到原始 AppDelegeate 文件中:

UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
    viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
    viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPhone" bundle:nil]; 
} else {
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil];
    viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil];
    viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];

然后我运行该项目并得到以下信息:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“ThirdViewController_iPhone”笔尖,但未设置视图出口。

如何设置插座?

4

1 回答 1

4

For your ThirdViewController_iPhone.xib, follow the instruction here. I think you need to do this step:

  • You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar
于 2012-07-31T09:13:34.990 回答