简体   繁体   English

iOS / Objective-C / Storyboard:防止ViewController模态启动

[英]IOS/Objective-C/Storyboard: Prevent ViewController From Launching Modally

I want a viewcontroller to launch using a show transition, not modally from the bottom. 我希望Viewcontroller使用显示过渡而不是从底部模态启动。 Normally when I use the following code that's what happens. 通常,当我使用以下代码时,会发生这种情况。 However, in this case, it is launching as a modal controller from the bottom up. 但是,在这种情况下,它是作为自下而上的模式控制器启动的。 Is there a switch I don't know about or could something be set in Storyboard that is causing this VC to launch modally from the bottom instead of showing? 是否有我不知道的开关,或者是否可以在情节提要中进行设置,导致该VC从底部以模态方式启动而不显示?

 UIStoryboard *storyBoard = self.storyboard;

    IDImportEventsOnboard *importEvents =
    [storyBoard instantiateViewControllerWithIdentifier:@"importEventsOnboard"];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: importEvents];

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

The VC is embedded in a navigation controller. VC嵌入在导航控制器中。

Should I be using showViewController directly to the targetVC without going through the Nav? 是否应该不通过Nav直接将showViewController直接用于targetVC? Or a pushViewController What is a proper, robust way to show a VC with a show transition? 还是pushViewController用显示转换来显示VC的正确,可靠的方法是什么?

Thanks in advance for any suggestions. 在此先感谢您的任何建议。

In the above code you are 'presenting' a new NavigationController from a ViewController. 在上面的代码中,您是从ViewController中“呈现”一个新的NavigationController。 In order to do a push/show transition, that needs to be done on an instance of a NavigationController. 为了进行推送/显示过渡,需要在NavigationController的实例上完成。 If your current ViewController is already in a NavigationController, you can push the new ViewController onto the current NavigationController stack. 如果当前的ViewController已经在NavigationController中,则可以将新的ViewController推送到当前的NavigationController堆栈中。 For Example: 例如:

UIStoryboard *storyBoard = self.storyboard;

IDImportEventsOnboard *importEventsVC =
[storyBoard instantiateViewControllerWithIdentifier:@"importEventsOnboard"];

[self.navigationController pushViewController:importEventsVC animated:YES];

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM