Passing parameters from one ViewController to other ViewController through a SWRevealViewController. This is not about passing parameter between Front Controller and Rear Controller, but from another ViewController (firstViewController) to the front (frontViewController. See image for reference. The segue (on button touch) tries to pass a string value to the front controller
image here: http://portwire.com/stackoverflow/storyboard.png
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SWRevealViewController *destinationViewController = (SWRevealViewController *)segue.destinationViewController;
UINavigationController *navegationController = (UINavigationController *)destinationViewController.frontViewController;
//UUPS!! SWRevealViewController.frontViewController is nil
//How to access destination UIViewController????????
FrontViewController * frontViewController = (FrontViewController *)navegationController.topViewController;
frontViewController.fromString = @"String from previous view";
}
For Swift 3.0:
You have to named storyBoardId for SWRevealViewController as any thing you want, in this example: "SWRevealViewController"
Follow this code below:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let revealVc = storyboard.instantiateViewController(withIdentifier :"SWRevealViewController") as! SWRevealViewController
revealVc.loadView()
let navViewController = revealVc.frontViewController as! UINavigationController
if (navViewController.topViewController?.isKind(of: MainVc.superclass()!)) {
let mainVc = navViewController.topViewController as! MainVc
mainVc.email = email
}
self.present(revealVc, animated: true, completion: nil)
I have first LoginViewController -> SWRevealViewController -> NavigationController -> HomeViewController (HomeViewController is the frontViewController)
From LoginViewController to SWRevealViewController I have a segue. To pass data,I use this code in prepareForSegue that works for me.
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";
} }
Hope that helps you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With