简体   繁体   English

ios / xcode / objective-c:导航到嵌入在导航控制器中的模态视图控制器

[英]ios/xcode/objective-c: Segue to modal view controller embedded in navigation controller

I have a segue from a button in a detail view controller to a new modal view controller that displays a map. 我有一个细节视图,从详细视图控制器中的按钮到显示地图的新模式视图控制器。

To pass the location to display on the map, I use preparetosegue as follows: 要传递位置以显示在地图上,我按如下方式使用preparetosegue:

if ([segue.identifier isEqualToString:@"showMap"]) {

        IDMapView *destViewController = segue.destinationViewController;   
            destViewController.contact=_contact;
             }

However, I after embedding the modal view controller in a navigation controller to implement a cancel button, the app is now crashing when I click on the button giving the error in the log: 但是,将模态视图控制器嵌入导航控制器以实现取消按钮后,我现在在单击日志中显示错误的按钮时崩溃了:

[UINavigationController setContact:]: unrecognized selector sent to instance 0x7f8738ea5ce0
(lldb) 

The error seems to have something to do with the navigation controller not having the property contact (which is on the view controller.) 该错误似乎与导航控制器没有属性contact(在视图控制器上)有关。

Can anyone suggest the right way to do this? 有人可以建议正确的方法吗?

The destinationViewController is now a UINavigationController and not an IDMapView . destinationViewController现在是UINavigationController而不是IDMapView You need to get the topViewController from the UINavigationController . 您需要从UINavigationController获取topViewController

if ([segue.identifier isEqualToString:@"showMap"]) {
    UINavigationController *navigationController = segue.destinationViewController;
    IDMapView *destViewController = navigationController.topViewController;   
    destViewController.contact=_contact;
}

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

相关问题 将变量传递给Objective-C中嵌入在导航控制器中的View Controller - Pass variable to View Controller Embedded in Navigation Controller in Objective-C Objective-C'找不到Segue'SegueIdentifier'的导航控制器 - Objective-C 'Could not find a navigation controller for segue 'SegueIdentifier' 搜索到嵌入有选项卡和导航控制器的视图控制器 - Segue to a view controller embedded with a tab and navigation controller ios / objective-c:从Textview创建Segue到Storyboard中的View Controller - ios/objective-c: Create Segue from Textview to View Controller in Storyboard Objective-C当前视图控制器及其导航控制器 - Objective-C Present View Controller with its Navigation Controller 在iOS中使用Objective-C推送序列的模态 - Modal to push segue with Objective-C in iOS 从模态(objective-c)引用视图控制器 - Reference presenting view controller from modal (objective-c) Objective-C:模态搜索和发布视图控制器 - Objective-C : Modal Segues and Releasing View Controller iOS / xcode / objective-c:如何在注册后实例化视图控制器 - iOS/xcode/objective-c: How to instantiate view controller after signup ios / xcode / objective-c:有什么方法可以链接到核心数据驱动页面中的其他视图控制器? - ios/xcode/objective-c: Any way to link to other view controller in core-data driven page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM