Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return to initial view controller when user logs out

I'm working on an app which uses Facebook integration, and the log in system works fine now. However, I can't seem to return to my initial view controller when the user clicks log out.

Here's an overview of my storyboard:

Screenshot of storyboard

I would like to return to the start when the user clicks the blue button (on the top). What would I do to achieve that? As you can see I have multiple Navigation Controllers, and I only use Push-seguesto get there. However, I do use the SWRevealViewController, which you can see in the middle.

I've tried [self.navigationController popToRootViewControllerAnimated:YES]; which doesn't do anything.

Any advice? Anyone familiar with the SWRevealViewController and what it might have done to my Navigation stack? Any help will be appreciated!

Thanks.

like image 521
Aleksander Avatar asked Mar 29 '14 03:03

Aleksander


People also ask

How do I switch between view controllers?

Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.

How do I segue to another view controller?

Well, in addition to that, Ctrl+dragging also helps set up segues. So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below.

How do I change the initial view controller in storyboard?

Specifying the Initial View Controllerstoryboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller. Checking this box will identify the selected view controller as the initial entry point for the storyboard you're on.


3 Answers

Try this,

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"NameOfYourStoryBoard" 
                                                     bundle:nil];
LoginViewController *add = 
           [storyboard instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];

[self presentViewController:add 
                   animated:YES 
                 completion:nil];
like image 121
Ramdhas Avatar answered Oct 05 '22 23:10

Ramdhas


Write Below Method in root viewcontroller

- (IBAction)returnToDashboard:(UIStoryboardSegue *)segue;

Give segue connection to destination view controller like below see in image

Give identifier to segue and assign method to that segue

Like below image

use below method in destination view controller

 [self performSegueWithIdentifier:@"pushtoDashboard" sender:self];
like image 35
Muralikrishna Avatar answered Oct 06 '22 00:10

Muralikrishna


First of all, I don't think you need that many UINavigationControllers. Using only one in your application should be enough. The reason popToRootViewController is not working in your case is because it will go to the first view controller withing a UINavigationController. You have nested many UINavigationControllers, thus when you click the blue button in the settings view controller it will go to the sidebar view controller (can't read it properly, the image is small).

You can do the following to get to the root view controller of your app:

UINavigationController *rootController =[(UINavigationController*)[(AppDelegate*)
        [[UIApplication sharedApplication]delegate] window] rootViewController]];

Replace AppDelegate with however it's called in your app.

But my advice is to remove all intermediate UINavigationControllers. Then just doing popToRootViewController should do the trick.

like image 40
Matías R Avatar answered Oct 06 '22 00:10

Matías R