目前,当点击按钮时,会出现UIModalPresentationSheet。当它向上滑动时,我想在它的顶部添加一个导航栏。我尝试过很多东西,但似乎没什么用。这是我正在尝试的内容,它会返回此错误。
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];
但它以模态方式推动它,并且没有modalpresentationsheet形式。如何才能使导航控制器的尺寸正确?
答案 0 :(得分:12)
尝试更改您的代码:
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];
因为在这里,您尝试从自身呈现addAthlete
。所以你得到这个错误。
答案 1 :(得分:4)
您应该展示您在其中包含addAthlete的navigationController。
[self presentViewController:navigationController animated:YES completion:nil];
答案 2 :(得分:0)
您将从当前的viewcontroller本身进行演示。
尝试类似的事情,
[self dismissViewControllerAnimated:YES completion:^{
[self.parentViewController presentViewController: navigationController animated:YES completion:nil];
}];