简体   繁体   English

将变量传递给Objective-C中嵌入在导航控制器中的View Controller

[英]Pass variable to View Controller Embedded in Navigation Controller in Objective-C

I have embedded a destination viewcontroller in a navigation controller and am now unable to pass it a variable. 我已经在导航控制器中嵌入了目标ViewController,现在无法将其传递给变量。

My code is: 我的代码是:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//THis is the navigation controller 
    UIViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:@"myNav"];
//This is the view controller embedded in the nav
    IDNowVC* myVC = [storyboard instantiateViewControllerWithIdentifier:@"myVC"];
   myVC.sender = @1;//for contacts

   [self presentViewController:destVC animated:YES completion:nil];

After the launch of the VC, sender property is nil. VC启动后,sender属性为nil。 It is not getting the value @1. 它没有得到值@ 1。

What am I missing? 我想念什么?

Thanks for any suggestions. 感谢您的任何建议。

In your code you have a comment that says: 在您的代码中,您有一条注释,内容为:

//This is the view controller embedded in the nav //这是嵌入到导航中的视图控制器

However, the view controller below that comment is not the one embedded in your navigation controller. 但是,该注释下方的视图控制器不是导航控制器中嵌入的视图控制器。 It's a completely new controller that is created at that line and disposed of at the end of the function. 这是一个全新的控制器,它在该行创建并在函数末尾废弃。

You need something more like this: 您需要这样的东西:

UINavigationController *destVC = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"myNav"];
IDNowVC* myVC = destVC.childViewControllers[0];
myVC.sender = @1; 

There might be some syntax issues with the above... 以上内容可能存在语法问题...

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

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