IOS SWRevealViewController - transferring data between controllers

I use SWRevealViewController to implement the slide menu (left) in the application. Everything is working fine, but now I am facing a small problem. I want to transfer data from my "main" view controller (the one that is completely visible, and I do not call it "frontViewController" because it seems that it is not front). I tried every possible opportunity that I can come up with in order to access the slide menu controller and pass data to it. Here is what I tried:

(MyControllerClass*)self.revealViewController.rearViewController
(MyControllerClass*)self.revealViewController.frontViewController

What I've tried things like self.revealViewController.navigationController[0], self.revealViewController.navigationController[1]also this self.revealViewController.viewControllers[0], self.revealViewController.viewControllers[1]. The next step was to implement prepareforsegueand listen to the identifier segue sw_frontand sw_rear. But not in these cases, I am right when I check isKindOfClass[MyControllerclass class]. I guess this is because they all are of type SWRevealViewController, right? And, prepareForSegue is not called at all, but everything is displayed correctly

The main question for me is: how can I transfer data between my side menu and my "main" (aka front-end) controller (otherwise it will also be good)?

thank

+4
source share
3 answers

. SWRevealViewController ( NavigationController). , ( ). :

UINavigationController* rearNavigationController = (UINavigationController*)self.revealViewController.rearViewController; 
//here you get the navigationController which is connected to the controller you want, in my case i want the rear controller

if ([rearNavigationController.topViewController isKindOfClass[MyCustomViewController]]) {
    MyCustomViewController* iWantYouController = (MyCustomViewController*)rearNavigationController.topViewController;
}

. ( )

+5

appdelegate, viewContollers. appdelegate, ,

@property (nonatomic, strong) NSArray *sharedItem;

firstViewContoller :

  AppDelegate *appDel = (AppDelegate*) [UIApplication sharedApplication].delegate;
  appDel.sharedItem = firstControllerObj;

VC :

AppDelegate *appDel = (AppDelegate*) [UIApplication sharedApplication].delegate;
  NSArray *receivingObj = appDel.sharedItem;
0

LoginViewController -> SWRevealViewController -> NavigationController -> HomeViewController (HomeViewController frontViewController), ViewControllers, SWRevealViewController

From LoginViewController to SWRevealViewController I use segue. For data transfer I use this code in prepareForSegue.

if ([[segue identifier] isEqualToString:@"homeVC"]) {

   SWRevealViewController *destination = [segue destinationViewController];
   [destination loadView];
   UINavigationController *navViewController = (UINavigationController *) [destination frontViewController];

   if ([navViewController.topViewController isKindOfClass:[HomeViewController class]]) {

      HomeViewController* homeVC = (HomeViewController*)navViewController.topViewController;
      homeVC.title = @"Test1";
    } 
}
0
source

Source: https://habr.com/ru/post/1569060/


All Articles