[英]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.