从普通视图切换到 TabBar 控制器

发布于 2024-08-15 12:21:21 字数 1041 浏览 8 评论 0原文

我构建了我的第一个 iPhone 应用程序,但在切换视图时遇到了问题。 首先,我有两个视图(登录、注册),它们通过“presentModalViewController:animated:”切换。

但如果有人登录,一定会有一种新的看法。我想在底部有一个 UITabBar (标签栏控制器)。但这是行不通的。我尝试创建一个新的 AppDelegate,以便我可以使用像这样需要 AppDelegate 的教程:

http://www.youtube.com/watch?v=LBnPfAtswgw&feature=player_embedded

切换到新控制器是这样完成的:

startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle:nil];
[UIView beginAnimations:@"View Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view addSubview:startViewController.view];
[UIView commitAnimations];

屏幕是白色的,因为显示的视图是 UIView在我的 StartView.xib 中。在那里我有新的 AppDelegate、文件的所有者、视图、TabBarController。但只加载了 UIView,而不加载 TabBarController。

你知道我如何解决这个问题吗?

谢谢&此致。

I build my first iPhone application and I have a problem with switching views.
First, I have two views (login, registration) which switch via "presentModalViewController:animated:".

But if someone logged in, there must be a new kind of view. I wanna have an UITabBar at the bottom (tab bar controller). But this does not work. I tried to create a new AppDelegate, so that I can use tutorials like this one which need a AppDelegate:

http://www.youtube.com/watch?v=LBnPfAtswgw&feature=player_embedded

The switch to the new controller is done like this:

startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle:nil];
[UIView beginAnimations:@"View Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view addSubview:startViewController.view];
[UIView commitAnimations];

The screen is white, because the shown view is the UIView in my StartView.xib. There I have the new AppDelegate, File's owner, View, TabBarController. But only the UIView is loaded and not the TabBarController.

Do you have an idea how I could this problem?

Thanks & Best Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假情假意假温柔 2024-08-22 12:21:21

我可能建议您从 TabBarController 开始,如果未设置用户名/密码,则活动 ViewController 执行 PresentModalViewController:animated: 以模式模式显示登录/注册视图控制器(隐藏底层 TabBarController)。

以下是一些以编程方式执行此操作的示例代码。

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 [window setBackgroundColor:[UIColor whiteColor]];

 tabBarController = [[UITabBarController alloc] init];


 aViewController = [[aViewController alloc] init];
 UINavigationController *aNavController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
 aNavController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
 [aViewController release];

 tabBarController.viewControllers = [NSArray arrayWithObjects: aNavController, nil];

 // Add the tab bar controller's current view as a subview of the window
    [window addSubview:tabBarController.view];

 if(userNotLoggedIn){
     [self displayLoginViewController];
 }


    [window makeKeyAndVisible];
}

- (void)displayLoginViewController {
 LoginViewController *controller = [[LoginViewController alloc] init];
 // setup controller
 [self.tabBarController presentModalViewController:controller animated:NO];
 [controller release];
}

I might suggest you start with a TabBarController, and if the username/password is not set, the active ViewController executes presentModalViewController:animated: to display the login/registration viewsControllers in modal mode (hidding the underliying TabBarController).

Here is some sample code for doing it programmatically.

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 [window setBackgroundColor:[UIColor whiteColor]];

 tabBarController = [[UITabBarController alloc] init];


 aViewController = [[aViewController alloc] init];
 UINavigationController *aNavController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
 aNavController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
 [aViewController release];

 tabBarController.viewControllers = [NSArray arrayWithObjects: aNavController, nil];

 // Add the tab bar controller's current view as a subview of the window
    [window addSubview:tabBarController.view];

 if(userNotLoggedIn){
     [self displayLoginViewController];
 }


    [window makeKeyAndVisible];
}

- (void)displayLoginViewController {
 LoginViewController *controller = [[LoginViewController alloc] init];
 // setup controller
 [self.tabBarController presentModalViewController:controller animated:NO];
 [controller release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文