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

时间:2009-12-15 14:40:13

标签: iphone views uitabbarcontroller switching

我构建了我的第一个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];

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

你知道我怎么能解决这个问题吗?

谢谢&最诚挚的问候。

1 个答案:

答案 0 :(得分:3)

我可能建议你从一个TabBarController开始,如果没有设置用户名/密码,活动的ViewController会执行presentModalViewController:animated:以模态模式显示登录/注册viewsControllers(隐藏底层的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];
}
相关问题