两个视图控制器之间的争论 [英] Segue between two view controllers

查看:113
本文介绍了两个视图控制器之间的争论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的身上故事板(如上所示),我有一个ViewController,它包含一个带注释的MKMapView。这些注释包含一个公开图标,当点击时,应该将用户导航到另一个ViewController。为此,我在视图控制器之间创建了一个推送segue。然后我给它一个'showDetail'的标识符并实现了以下代码。

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.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [self performSegueWithIdentifier:@"showDetail" sender:self];
}

但是我收到以下错误。

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.'

其中我错了?我已经尝试将我的源UIViewController更改为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的根控制器(或从具有navcontroller的视图控制器推送)。要做到这一点

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


  • 将一个新的导航控制器拖到你的故事板中 - 它将通过
    默认附加到一个tableview控制器

  • 删除tableview控制器右键单击导航
    控制器,并将Root View Controller属性连接到
    现有视图控制器

  • 将输入点箭头从视图控制器移动到根
    视图控制器

这篇关于两个视图控制器之间的争论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆