[英]hide UITabBarController's tab bar when pushing UIViewController
我有一個標簽欄應用程序。 這是啟動代碼
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
不起作用。 請幫我,怎么辦?
我希望這可以幫助你:
- (void)viewWillAppear: (BOOL)animated
{
self.hidesBottomBarWhenPushed = YES;
}
如果您不希望主視圖顯示選項卡欄,則不應將其推到導航控制器上。 這樣做會使應用程序假定此新控制器是導航層次結構的一部分。 最好的解決方案可能是在RootViewController上啟動您的應用程序,然后以模態顯示導航控制器。 完成導航控制器的操作后,讓它自己調用dismissModalViewController
。
是的,您必須在窗口上而不是tabBar的viewcontroller上添加modalview。 嘗試類似的事情..使AppDelegate成為對象,例如: AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate];
然后在下一行中添加
[appDelegate.window.rootviewcontroller.view presentModalViewController:vController animated:YES];
或在tabBar的firstviewcontroller的viewDidAppear中添加您的代碼[self presentModalViewController:vController animated:YES]
animation [self presentModalViewController:vController animated:YES]
。
您為解決問題做了什么?我也想知道。
使用以下代碼解決:
-(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 Developer
UIViewController *nextViewController = [[UIViewController alloc] initWithNibName:@"NextViewController" bundle:[NSBundle mainBundle]];
// hide UITabbarController
nextViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:nextViewController animated:YES];
[nextViewController release];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.