MBX
MBX

Reputation: 828

PopToViewController shows the right ViewController, but the wrong navigationbar

I have an application where the first view is a login screen, and the username and password is used for authentication all around the application. If something go wrong in the authentication process, the user will be thrown back to the login screen, but if the problem occurs when the user press the back button in the navigation bar, the application is showing the login screen correct, but the navigation bar will show the buttons from the view it was supposed to show.

Example: If a user press the back button on View B, and the application is supposed to show View A, but something went wrong, the application will show the login screen, but the navigation bar is the one from View A.

I have tried a couple of things, but the thing that came closest was: In the ViewWillDisappear for View B:

        NSArray * nc = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[nc objectAtIndex:0] animated:YES];

And it gave the result discribed above.

Upvotes: 2

Views: 894

Answers (2)

Ankur
Ankur

Reputation: 1

Remove the login screen after sucessful login [self.window removeFromsuperview] Then it will remove login screen from naviagation. Accept my ans if it happens thank u

Upvotes: -1

Ashbay
Ashbay

Reputation: 1661

In your LoginController override the viewWillAppear: methods and set the navigation bar button as you want :

-(void) viewWillAppear:(BOOL) animated
{
  [super viewWillAppear:animated];

  //Example :
  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"AText" style:UIBarButtonItemStyleBordered target:self action:@selector(anAction)];
}

If you don't use ARC remember to add autorelease to the leftBarButton Item :

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"AText" style:UIBarButtonItemStyleBordered target:self action:@selector(anAction)] autorelease];

Upvotes: 2

Related Questions