【问题标题】:PresentViewController hides Navigation bar in iOSPresentViewController 在 iOS 中隐藏导航栏
【发布时间】:2014-08-27 04:39:39
【问题描述】:

当我呈现PresentViewController 以导航屏幕时,我正在尝试显示导航控制器。我解决了这个问题,但我遇到了另一个问题。问题是当我按下一个屏幕时,时间后退按钮在导航控制器的下一个屏幕上可见。但是当我尝试PresentViewController 时,导航栏是可见的,但不是返回按钮。

这是我的代码:

 - (IBAction)clickMeAction:(id)sender
 {
    ViewController1 *viewcontrol = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewID"];
    //[self.navigationController pushViewController:viewcontrol animated:YES]; // this is for push to viewcontroller


    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewcontrol];
    [self presentViewController:navigationController animated:YES completion:nil]; // This is for modalviewcontroller
 }

这是我的输出:

带推:

带模态:

请帮帮我。

【问题讨论】:

  • 当您以模态方式打开一个窗口时,无论是 Navigation Contoller 还是其他任何它都不会显示 Back 按钮,您必须手动设置它。
  • 是的,它是一个导航控制器。
  • 模态打开NC时没有返回按钮,需要手动设置。
  • @SRNayak 因为当您以模态方式打开任何 VC 时,内存中没有 VC 堆栈,但是使用导航控制器会在内存中创建 VC 堆栈以推送和弹出。
  • 我认为@YogeshSuthar 试图传达的是,对于模态视图控制器,默认情况下不会显示后退按钮。这是苹果的设计。当您呈现一个模态视图时,它看起来像是呈现在当前视图之上,因此没有后退按钮。不过,您可以创建自己的栏按钮项来关闭视图。

标签: ios uinavigationcontroller


【解决方案1】:

方法一:

[navigationController presentViewController:navigationController animated:YES completion:^{
             [navigationController setNavigationBarHidden:YES animated:NO];
        }];

方法二:在presentViewController中

- (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        self.navigationController.navigationBarHidden = YES;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多