2012-06-26 33 views
0

我有一個標籤欄應用程序。 這裏的啓動代碼當推UIViewController時隱藏UITabBarController的標籤欄

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // Override point for customization after application launch. 
    [self.window makeKeyAndVisible]; 



    self.tabBarController=[[UITabBarController alloc] init]; 


    StartViewController *startViewController=[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil]; 
    NavRootViewController *navRootViewController=[[NavRootViewController alloc] initWithNavControllerWithSubViewController:startViewController]; 

    HelpViewController *helpViewController=[[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil]; 

    SettingsViewController *settingsViewController=[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil]; 

    AboutUsViewController *aboutUsViewController=[[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil]; 

    [self.tabBarController setViewControllers:[NSArray arrayWithObjects: navRootViewController, helpViewController, settingsViewController, aboutUsViewController, nil]]; 



    [[UIApplication sharedApplication] setStatusBarHidden:YES]; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    self.window.rootViewController=self.tabBarController; 

應用程序啓動與4標籤欄選項卡。之後用戶按下啓動第一個選項卡的導航控制器的根視圖控制器

-(IBAction)startPressed:(id)sender 
{ 
    NSLog(@"startPressed: called"); 


    RootViewController *vController=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 
    [self.navigationController pushViewController:vController animated:YES]; 

} 

這工作正常按鈕,但我需要隱藏標籤欄我RootViewController 財產hidesBottomBarWhenPushed不起作用 這個動作被調用。 請幫我,怎麼辦?

+2

出示您的根視圖作爲modalviewcontroller.That會隱藏下面的tabBar。 –

+0

你在哪裏分配了hidesBottomBarWhenPushed? – Apurv

+0

@iPhoneDeveloper如果我調用'[self presentModalViewController:vController animated:YES]'標籤欄保持可見狀態。有什麼問題。我做錯了什麼? – user1385666

回答

1

是啊,你必須添加窗口上的modalview不上的TabBar的視圖 - 控制。 試着這麼做..作出的AppDelegate的對象,如: AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate]; 然後在下一行添加

[appDelegate.window.rootviewcontroller.view presentModalViewController:vController animated:YES]; 

或的TabBar的firstviewcontroller的viewDidAppear添加代碼[self presentModalViewController:vController animated:YES]

你做了什麼來解決問題??我也想知道。

1

如果你不希望主視圖顯示標籤欄,你不應該推到導航控制器。這樣做會導致應用程序假定這個新控制器是導航層次結構的一部分。最好的解決方案可能是在RootViewController上啓動應用程序,然後以模態方式呈現導航控制器。當您完成導航控制器的操作時,請自行撥打dismissModalViewController

+0

困難有點明白:( – user1385666

+0

爲了避免誤解,我將解釋層次一次。 – user1385666

+0

應用程序啓動與4卡口與第一選項卡中選擇標籤欄。 – user1385666

5

我希望這可以幫助你:

- (void)viewWillAppear: (BOOL)animated 
{ 
    self.hidesBottomBarWhenPushed = YES; 
} 
1

使用此代碼解決:

-(IBAction)startPressed:(id)sender 
{ 
    NSLog(@"startPressed: called"); 

    RootViewController *vController=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 
    UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:vController]; 
    [vController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
    [((AppDelegate *)[UIApplication sharedApplication].delegate).tabBarController presentModalViewController:navController animated:YES]; 
} 

由於@iPhone開發

0
UIViewController *nextViewController = [[UIViewController alloc] initWithNibName:@"NextViewController" bundle:[NSBundle mainBundle]]; 

// hide UITabbarController 
nextViewController.hidesBottomBarWhenPushed = YES; 

[self.navigationController pushViewController:nextViewController animated:YES]; 
[nextViewController release];