如何将自己分配给另一个 class 对象,同时导航到另一个视图控制器而不使用 segue

How to assign self to another class object, while navigating to another view controller with out segue

我正在使用下面的代码导航到另一个视图控制器,我想将这个 self 分配给另一个 class 的委托,我该怎么做?

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

UINavigationController *controller = [storyboard instantiateViewControllerWithIdentifier:@"storyBoardID"];

self.navigationController presentViewController:controller animated:YES completion:nil];

从导航控制器获取视图控制器

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];