gpt4 book ai didi

iphone - 将 ViewController 放在 TabBarController 之上

转载 作者:行者123 更新时间:2023-11-28 20:43:41 25 4
gpt4 key购买 nike

基本上,我想在显示 TabBarController 之前在我的 iPhone 应用程序中创建一个登录屏幕。我尝试了以下方法,首先将我的 TabBarController 添加到窗口 subview ,然后在我的 LoginViewController 之上。我做错了什么,还是应该完全不同?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];

NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];

DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
dvc_nc.tabBarItem.title = @"Home";
//dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];

OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
ovc_nc.tabBarItem.title = @"Option";
//ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Option" ofType:@"png"]];

[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];

UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];

[self.window addSubview:self.tabController.view];

LoginViewController *lvc = [[OptionsViewController alloc] init];
UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.window addSubview:lvc_nc.view];
[lvc release];
[lvc_nc release];

return YES;
}

最佳答案

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];

NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];

DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
dvc_nc.tabBarItem.title = @"Home";
//dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];

OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
ovc_nc.tabBarItem.title = @"Option";
//ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Option" ofType:@"png"]];

[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];

UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];

[self.window addSubview:self.tabController.view];

LoginViewController *lvc = [[OptionsViewController alloc] init];
UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.tabController presentModalViewController:lvc_nc animated:no];
[lvc release];
[lvc_nc release];

return YES;
}

关于iphone - 将 ViewController 放在 TabBarController 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7332198/

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