Michal Michal - 1 year ago 286
Swift Question

LogOut button creates back button

I created a button in my

as a Left Bar Button Item to log the current user out and segue and to the login

The problem is that tapping it creates a back button on the login
and user can come back to the previous view.

Answer Source

Your flow of navigation controller of app is wrong i think. Login view controller should be rootview controller of navigation controller or it should be initial view controller. You have another viewcontroller something like Wybierz miasto !! It shouldn't like this.

You can call

 [self.navigationController popToRootViewControllerAnimated:YES]; 

from any view controller of navigation stack to go rootview controller. (i.e. logout).

If you must require flow like this then you can hide and show backbutton like,

  self.navigationItem.hidesBackButton = YES; //NO for show

If you want to hide navigation bar for particular view controller you can do like


     [self.navigationController.navigationBar setHidden:YES];


  [self.navigationController.navigationBar setHidden:NO];

Update in swift as asked in comment

    self.navigationItem.hidesBackButton = true




  override func viewWillAppear(animated: Bool) {
    self.navigationController!.navigationBar.hidden = true

override func viewDidDisappear(animated: Bool) {
    self.navigationController!.navigationBar.hidden = false

Avoid mistakes in swift if any! Not much familiar with swift!

Hope this will help :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download