oyatek oyatek - 4 months ago 106
iOS Question

SWRevealViewController - manually switch to another view?

I have a sidebar menu, made with SWRevealViewController.

One of menu elements in sidebar is "sign-in". It opens sign-in view (via custom SWRevealViewController segue).

I want to programmatically switch to another view after user successfully signs in. How do I do that?

UPDATE, my code:

ViewController *vc = [[ViewController alloc] init]; // this is main front ViewController
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:vc animated:YES];


After this I get just empty screen. What am I doing wrong? I feel that this is wrong:

ViewController *vc = [[ViewController alloc] init];


so what is correct way to access already loaded view controller? (it loads at app start by SWRevealViewController as front controller)

Answer

Use - (void)setFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated; method

SWRevealController has it's own property you can access from any UIViewController:

SWRevealViewController *revealController = self.revealViewController;

You can check example projects at it's GitHub repository: https://github.com/John-Lluch/SWRevealViewController