gpt4 book ai didi

objective-c - 如何将手动创建的 ViewController 链接到 TabBar 应用程序

转载 作者:行者123 更新时间:2023-11-28 19:19:06 26 4
gpt4 key购买 nike

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

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

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

我想创建一个新的 View Controller “ViewController3”,但在文件创建过程中,我只能选择为 iPad 创建或仅为 iPhone 创建(选中“Targeted for iPad”)。我需要 iPhone 和 iPad xibs,就像为我创建的 FirstViewController 和 SecondViewControllers 一样。所以我决定手动创建 xib,并在没有 xib 的情况下继续创建文件。

所以在那之后我自然而然地继续手动创建 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”nib 但未设置 View 导出。”

如何设置 socket ?

最佳答案

对于您的 ThirdViewController_iPhone.xib,请遵循说明 here .我认为您需要执行此步骤:

  • You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar

关于objective-c - 如何将手动创建的 ViewController 链接到 TabBar 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10404136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com