我使用下面的代码导航到另一个视图控制器,我想将此self分配给另一个类的委托,我该怎么做?
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *controller = [storyboard instantiateViewControllerWithIdentifier:@"storyBoardID"];
self.navigationController presentViewController:controller animated:YES completion:nil];
答案 0 :(得分:0)
从导航控制器获取视图控制器
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *controller = [storyboard instantiateViewControllerWithIdentifier:@"navigationControllerID"];
TargetVC *targetVC = (TargetVC *)controller.viewControllers.firstObject
//OR
TargetVC *targetVC = (TargetVC *)controller.topViewController;
targetVC.mydelegate = self;
[self.navigationController presentViewController:controller animated:YES completion:nil];
从TabBar控制器获取视图控制器
UITabBarController *homeTabBar=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"homeTabBarID"];
TargetVC *targetVC =nil;
UINavigationController *nav = [homeTabBar.viewControllers objectAtIndex:0];
//if you have multiple tab then you can give Index as per your ViewController
targetVC =(TargetVC*)[nav.viewControllers objectAtIndex:0];
targetVC.mydelegate = self;
[self.navigationController presentViewController:homeTabBar animated:YES completion:nil];