如何在呈现UINavigationController时将属性传递给根视图控制器?

时间:2015-04-23 14:28:15

标签: ios objective-c browser uinavigationcontroller

我正在应用内置浏览器,使用来自app中任何viewController的safari打开链接。 这是用于在AppDelegate.m

中启动带链接的浏览器的代码
-(void)openExternalRef:(NSString *)ref
{
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
   CSDBrowser* browser = [storyboard instantiateViewControllerWithIdentifier:@"CSDBrowser"];
   browser.urlString = ref;
   browser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
   [self.window makeKeyAndVisible];
   UINavigationController* navi = [storyboard instantiateViewControllerWithIdentifier:@"CSDBrowserNavi"];

   [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
   [self.window.rootViewController.navigationController pushViewController:browser animated:YES];

}

我需要将变量“ref”传递给我的viewcontroller,但我需要先启动导航控制器,任何想法?

1 个答案:

答案 0 :(得分:0)

   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

[self.window makeKeyAndVisible];
UINavigationController* navi = [storyboard instantiateViewControllerWithIdentifier:@"CSDBrowserNavi"];

CSDBrowser* browser = [navi viewControllers][0];
browser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

browser.urlString = ref;

[self.window.rootViewController presentViewController:navi animated:YES completion:nil];