ios 两个视图控制器之间的转场
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13049668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Segue between two view controllers
提问by Jonathan
On my storyboard (shown above), I have a ViewController which holds an MKMapView with annotations. These annotations hold a disclosure icon, which when tapped, should navigate the user to another ViewController. To do so I've created a push segue between the view controllers. I've then given it an identifier of 'showDetail' and implemented the following code.
在我的故事板(如上所示)上,我有一个 ViewController,其中包含一个带注释的 MKMapView。这些注释包含一个显示图标,当点击该图标时,应将用户导航到另一个 ViewController。为此,我在视图控制器之间创建了一个 push segue。然后我给它一个“showDetail”标识符并实现了以下代码。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"showDetail" sender:self];
}
However I get the following error.
但是我收到以下错误。
Could not find a navigation controller for segue 'showDetail'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
Where am I going wrong? I have tried changing my source UIViewController to a UINavigationController, but the view then just displays as a black screen.
我哪里错了?我曾尝试将我的源 UIViewController 更改为 UINavigationController,但该视图仅显示为黑屏。
回答by Aran Mulholland
Simplest way to do this is to select the View controller you want to be the root of your navigation hierarchy and choose
最简单的方法是选择您想要作为导航层次结构根的视图控制器,然后选择
Editor > Embed In > Navigation Controller
This creates the new navigation controller and hooks up everything up for you.
这将创建新的导航控制器并为您连接所有内容。
回答by Edwin Iskandar
You actually have to set your UIViewController as the root controller of a UINavigationController (or pushed through from a view controller w/ a navcontroller). To do that
您实际上必须将 UIViewController 设置为 UINavigationController 的根控制器(或从带有导航控制器的视图控制器推送)。要做到这一点
- Drag a new navigation controller into your storyboard - it will by default be attached to a tableview controller
- Delete the tableview controller Right click on the navgiation controller, and connect the "Root View Controller" property to your existing view controller
- Move the entry point arrow from your view controller to the root view controller
- 将一个新的导航控制器拖到您的故事板中 - 默认情况下它将附加到一个 tableview 控制器
- 删除 tableview 控制器右键单击导航控制器,并将“根视图控制器”属性连接到您现有的视图控制器
- 将入口点箭头从视图控制器移动到根视图控制器
回答by Raj Kumar
check this steps: 1. to click connection between two view controller. 2. click attribute inspector 3. set identifier to "showDetail". 4. save and run.
检查此步骤: 1. 单击两个视图控制器之间的连接。2. 单击属性检查器 3. 将标识符设置为“showDetail”。4.保存并运行。