简体   繁体   English

两个视图控制器之间的争论

[英]Segue between two view controllers

在此输入图像描述

On my storyboard (shown above), I have a ViewController which holds an MKMapView with annotations. 在我的故事板上(如上所示),我有一个ViewController,它包含一个带注释的MKMapView。 These annotations hold a disclosure icon, which when tapped, should navigate the user to another ViewController. 这些注释包含一个公开图标,在点击时,应该将用户导航到另一个ViewController。 To do so I've created a push segue between the view controllers. 为此,我在视图控制器之间创建了一个push segue。 I've then given it an identifier of 'showDetail' and implemented the following code. 然后我给它一个'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,但视图只显示为黑屏。

Simplest way to do this is to select the View controller you want to be the root of your navigation hierarchy and choose 最简单的方法是选择要作为导航层次结构根目录的View控制器并选择

Editor > Embed In > Navigation Controller

This creates the new navigation controller and hooks up everything up for you. 这将创建新的导航控制器并为您提供所有内容。

You actually have to set your UIViewController as the root controller of a UINavigationController (or pushed through from a view controller w/ a navcontroller). 实际上,您必须将UIViewController设置为UINavigationController的根控制器(或者从具有navcontroller的视图控制器推送)。 To do that 要做到这一点

  • Drag a new navigation controller into your storyboard - it will by default be attached to a tableview controller 将新的导航控制器拖到故事板中 - 默认情况下会将其附加到tableview控制器
  • Delete the tableview controller Right click on the navgiation controller, and connect the "Root View Controller" property to your existing view controller 删除tableview控制器右键单击导航控制器,并将“Root View Controller”属性连接到现有的视图控制器
  • Move the entry point arrow from your view controller to the root view controller 将入口点箭头从视图控制器移动到根视图控制器

check this steps: 1. to click connection between two view controller. 检查以下步骤:1。单击两个视图控制器之间的连接。 2. click attribute inspector 3. set identifier to "showDetail". 2.单击属性检查器3.将标识符设置为“showDetail”。 4. save and run. 4.保存并运行。

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

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