简体   繁体   English

模态视图中的导航控制器

[英]Navigation controller in modal view

Currently, when a button is tapped, a UIModalPresentationSheet comes up. 目前,当点击按钮时,会出现UIModalPresentationSheet。 I'd like to add a navigation bar at the top of this when it slides up. 当它向上滑动时,我想在它的顶部添加一个导航栏。 I've tried a lot of things but nothing seems to work. 我尝试过很多东西,但似乎没什么用。 Here's what i'm currently trying and it returns this error. 这是我正在尝试的,它会返回此错误。

    AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
    //[self.navigationController pushViewController:addAthlete animated:YES];

    addAthlete.delegate = self;
    addAthlete.modalPresentationStyle = UIModalPresentationFormSheet;
  //  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
    [self presentViewController:navigationController animated:YES completion:nil];

But it pushes it up modally, and without the modalpresentationsheet form. 但它以模态方式推动它,并且没有modalpresentationsheet形式。 How can I make it so the navigation controller is sized correctly? 如何才能使导航控制器的尺寸正确?

Try to change your code like this : 尝试更改您的代码,如下所示:

    AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];

    addAthlete.delegate = self;
    navigationController.modalPresentationStyle = UIModalPresentationFormSheet;


    [self presentViewController:navigationController animated:YES completion:nil];

Because here, you try to present addAthlete from itself. 因为在这里,您尝试从自身呈现addAthlete So you get this error. 所以你得到这个错误。

您应该展示您在其中包含addAthlete的navigationController。

[self presentViewController:navigationController animated:YES completion:nil];

You are presenting from current viewcontroller itself. 您将从当前的viewcontroller本身进行演示。

Try something like, 试试像,

[self dismissViewControllerAnimated:YES completion:^{
   [self.parentViewController presentViewController: navigationController animated:YES completion:nil];
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带导航控制器的模态视图 - Modal View with Navigation Controller 模态视图控制器上的导航栏 - Navigation Bar on Modal View Controller 导航栏下的模态视图控制器-Swift - Modal view controller under Navigation Bar - Swift 呈现模态视图 Controller 隐藏导航栏 - Presenting a Modal View Controller hides the Navigation Bar 以编程方式将导航控制器嵌入到模式视图控件中 - Embed navigation controller in modal view contriller programatically 在呈现模态视图控制器之后推动导航控制器 - Pushing a navigation controller after a modal view controller is presented 是否可以快速从模态视图选择到导航控制器上不在层次结构中的视图? - Is it possible to segue from a modal view to a view that is not in the hierarchy on a Navigation Controller in swift? 如何使用导航控制器在模式视图中辞职第一响应者? - How do I resign a first responder in a modal view with a Navigation Controller? 在导航控制器内部重用视图,并使用情节提要作为模式弹出窗口 - Reusing view inside navigation controller and as a modal popup with storyboards 无法设置模态视图控制器的导航栏颜色 - Unable to set navigation bar color of modal view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM