gpt4 book ai didi

iphone - Xcode 4 中没有 mainwindow.xib 困惑如何让我的 TabBarController 使用 NavigationController

转载 作者:行者123 更新时间:2023-12-03 18:52:18 25 4
gpt4 key购买 nike

这在 Xcode 3 中非常简单。但我完全迷失在 Xcode 4 中。* 看起来 IB 根本没有被使用。所有TabBarController代码都在代码中。

问题:如何将 NavigationBarController 添加到使用 TabBarController 模板时 Xcode 生成的默认代码中?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];

return YES;

}

最佳答案

正如有人提到的,您可以添加一个 xib 文件并配置应用程序以使用它。这是代码版本,如果您决定走这条路,最好了解一下任何一种方式

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *viewController1 = [[FirstViewController alloc] init];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
[viewController1 release]; viewController1 = nil;

UIViewController *viewController2 = [[SecondViewController alloc] init];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
[viewController2 release]; viewController2 = nil;

self.tabBarController = [[UITabBarController alloc] init];

NSArray *viewController = [[NSArray alloc] initWithObjects:navigationController1, navigationController2, nil];
[navigationController1 release]; navigationController1 = nil;
[navigationController2 release]; navigationController2 = nil;

self.tabBarController.viewControllers = viewControllers;
[viewControllers release]; viewControllers = nil;

self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];

return YES;
}

这是在浏览器中编写的,但应该可以工作。

关于iphone - Xcode 4 中没有 mainwindow.xib 困惑如何让我的 TabBarController 使用 NavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7408108/

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