2011-12-15 92 views
-2

這是一個基於視圖的應用程序。如何在登錄屏幕啓動後顯示標籤欄控制器?

在delegate.m文件

我曾經做過這樣的發動最初的登錄界面:

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 

    LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil]; 

    [window addSubview:loginView.view]; 
} 

通過添加上面的代碼我都推出了登錄界面成功地,但在我的登錄屏幕的底部,我可以看到留下一個空間。

如何能在標籤欄控制器獲得SUCESSFUL登錄後推出?

我在LoginView.m文件creatd的方法稱爲登錄:

-(void)login 
{ 
    if(login) 
    { 
    TabBarController *tabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil]; 

    [self.view addSubView: aTabBarController.view]; 
    } 

    [aTabBarController release]; 

請大家幫我出這個與相應的代碼。

+0

這個問題的可能的複製:http://stackoverflow.com/ question/6034893/show-a-login-screen-a-tab-bar-controller – Niko 2011-12-15 10:40:05

+0

你需要接受你之前提出的問題的答案如果你不能接受他們的答案,那麼讓人們努力回答你的問題是令人沮喪的。 – 2011-12-15 11:16:58

回答

1

你必須建立在類似的appDelegate方法..並在appDelegate.h你必須創建這樣

的UITabBarController * Obj_tabbar的對象;

,然後在.m文件,

-(void) switchToTabbarController  
{  
    Obj_tabbar.delegate = self; 
    Obj_tabbar.selectedIndex = 0; 
    Tracking_HomeVC *obj = [[Tracking_HomeVC alloc]init]; 
    [self tabBarController:Obj_tabbar didSelectViewController:obj]; 
    [self.window addSubview:Obj_tabbar.view]; 

}

//此時Tracking_HomeVC是TabbarController的第一視圖控制器。它會被添加到窗口。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 

{

if([tabBarController selectedIndex] == 0) 
    { 
     //Write your code here to do with the first view controller object. 
    } 

}

,然後從你的LoginView這樣稱呼它..

-(void)LoginPressed  
{  
    AppAppDelegate *delegate =(AppAppDelegate *) [[UIApplication sharedApplication] delegate]; 
    [delegate switchToTabbarController];  
} 
1

您的登錄視圖(或它的控制器,如果你有一個,它看起來像你沒有)應該告訴的appDelegate來交換RootViewController的是一個taBarController。你不希望loginview試圖添加一個tabBar作爲它自己的孩子。

1

做它在您的appdelegate創造一個像正常的一tabbarcontroller並將其設置爲RootViewController的方法之一:

TOTabBarController *tabBarController = [[TOTabBarController alloc] init]; 

UIViewController *vc1 = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 
UIViewController *vc3 = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 

UINavigationController *vc2_nc = [[UINavigationController alloc] initWithRootViewController:vc2]; 
UINavigationController *vc3_nc = [[UINavigationController alloc] initWithRootViewController:vc3]; 

NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2_nc, vc3_nc, nil]; 

[tabBarController setViewControllers:viewControllers]; 

//set tabbarcontroller as rootviewcontroller 
[[self window] setRootViewController:tabBarController]; 

然後在登錄屏幕顯示模態(無動畫),如果用戶沒有登錄:

if (not logged in) { 
    UIViewController *lvc_nc = [[UIViewController alloc] init]; 
    [[[self window] rootViewController] presentModalViewController:lvc_nc animated:NO]; 
} 

希望幫助!

+0

感謝您的回答球員我會嘗試 – 2011-12-15 11:54:42