![](/img/trans.png)
[英]Pass variable to View Controller Embedded in Navigation Controller in Objective-C
[英]ios/xcode/objective-c: Segue to modal view controller embedded in navigation controller
我有一個細節視圖,從詳細視圖控制器中的按鈕到顯示地圖的新模式視圖控制器。
要傳遞位置以顯示在地圖上,我按如下方式使用preparetosegue:
if ([segue.identifier isEqualToString:@"showMap"]) {
IDMapView *destViewController = segue.destinationViewController;
destViewController.contact=_contact;
}
但是,將模態視圖控制器嵌入導航控制器以實現取消按鈕后,我現在在單擊日志中顯示錯誤的按鈕時崩潰了:
[UINavigationController setContact:]: unrecognized selector sent to instance 0x7f8738ea5ce0
(lldb)
該錯誤似乎與導航控制器沒有屬性contact(在視圖控制器上)有關。
有人可以建議正確的方法嗎?
destinationViewController
現在是UINavigationController
而不是IDMapView
。 您需要從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.