显示/隐藏选项卡栏

3
大家好,我有一个问题,一直在寻找解决方案但未能找到。我正在开发一个基于选项卡的应用程序。问题是我想在第一个屏幕隐藏选项卡,然后在显示第一个屏幕后显示它在所有其他屏幕上。
请问是否有人能给我最好的解决方案?
实际情况是我有一个登录屏幕,我不想在这里显示选项卡,因为只有用户登录后才会显示选项卡及其内容。当用户登录后,我希望选项卡被显示并显示其内容。
最好的问候。

请参考此处的优秀答案:隐藏选项卡栏在推送视图时 - Tomer Even
2个回答

5
如果您的标签栏控制器是您的rootController,那么可以使用rootController.selectedIndex = 0来选择第一个选项卡项目,然后使用rootController.selectedIndex = 1;等等选择其他选项卡项目。一旦特定视图加载完成,您可以将其他视图加载到数组中,然后将其添加到rootController.selectedIndexreloadInputViews中进行动画。 编辑:(按照评论)
所以您有一个标签栏控制器,并且您想在启动应用程序时显示介绍和登录屏幕。如果登录成功,您想呈现标签栏控制器!这可以通过ModalViewControllers完成。
  1. In the ViewDidLoad of the view that loads up first, (it's your first tab by default), add

    //Declare Introduction Screen//
    
    IntroductionController *introductionController = [[IntroductionController alloc] initWithNibName:@"IntroductionController" bundle:[NSBundle mainBundle]];
    
    //Give a navigation screen for your introduction screen and set it to introduction screen
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:introductionController];
    
    navController.title = @"Introduction";
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:navController animated:NO];
    
  2. Now your introduction screen would load as soon as your first tab bar loads. But the loading is instantaneous, so it's not visible to the user's eye. Now reference your Login View Controller like @class LoginController and create an object LoginViewController *lvc;, and synthesize it. Now declare LoginButton and in the IBAction

    -(IBAction) loginAction: (id) sender{
    
     NSLog(@"I clicked Login");
    
     if (self.lvc ==nil){
        self.lvc = [[LoginController alloc] init ];
    
     }
    
     lvc.title = @"Login";
     [self.navigationController pushViewController: self.lvc animated:YES];
    
    
     }
    
  3. And in the LoginViewController, if Login is successful, just do

    [self dismissModalViewControllerAnimated:YES];
    

如果我有两个屏幕,一个是介绍屏幕,另一个是登录屏幕,我不想显示选项卡栏怎么办? :-( 介绍屏幕包含一个“登录”按钮。当我们按下此按钮时,登录屏幕会出现。我不希望这两个屏幕上都有选项卡栏。您的解决方案适用于1个屏幕。谢谢。 - Aqueel
我认为我对你想做的事情有一个好主意。如果我上面的评论没有意义,请告诉我,我可以修改答案。 - Legolas
是的,请修改您的答案。谢谢。 - Aqueel
好的,在编辑我的答案之前,告诉我我是否正确理解了您想要的内容 - 您有一个带有多个选项卡的选项卡控制器。您想展示应用程序的介绍和登录屏幕,并且只有在登录成功后才想显示选项卡控制器。这些我理解得对吗?(现在先不考虑隐藏选项卡。) - Legolas
是的,绝对正确。但请注意,我没有实现导航控制器。所以我认为pushViewController将不起作用。我是对的吗? - Aqueel
显示剩余11条评论

-2
创建一个uitabbar的outlet,然后在第一个屏幕中声明它为隐藏状态,接着创建一个新的void,在第一个屏幕中不要发送它,让它显示“hide”。在hide函数内部,加入代码uitabbar.hidden = YES; 然后,在其他视图中使其生效,在viewDidLoad中写入以下代码:
 [(//first view*)[UIApplication sharedApplication].delegate //the void, in this case, hide];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接