2009-12-15 81 views
0

我構建了我的第一個iPhone應用程序,並遇到切換視圖的問題。 首先,我有兩個視圖(登錄,註冊)通過「presentModalViewController:animated:」切換。從普通視圖切換到TabBar控制器

但是,如果有人登錄,必須有一種新的看法。我想在底部有一個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,文件的所有者,查看,TabBarController。但只有UIView被加載,而不是TabBarController。

你有一個想法,我怎麼會這個問題?

感謝&最好的問候。

回答

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]; 
} 
+0

非常感謝您的回覆。 但是,對不起,我不知道你的意思。我應該在MainWindow.xib中創建一個TabBarController。所以如果我啓動應用程序,底部的TabBar將顯示,而不是我的登錄視圖或註冊視圖?! – Tim 2009-12-15 15:46:50

+0

沒錯,當應用程序啓動TabBarController將被加載,並從firstViewController列入TabBarController,你檢查的用戶名/密碼,如果沒有設置,執行presentModalViewController顯示loginViewController,就應該這麼快的TabBarControllwe幾乎看不到你需要的效果。 – 2009-12-15 15:50:53

+0

是的,但是,如果應用程序啓動,將顯示登錄屏幕。用戶必須先登錄,因此第一個屏幕始終是登錄屏幕。如果有人登錄成功,我需要切換它。 – Tim 2009-12-15 16:38:57

相關問題