[英]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.