0

I've created my Storyboard with a LoginViewController which is set as the RootViewController. If the user is already logged then I just segue to the HomeViewController.

The problem is on the HomeViewController. I don't want the user to navigate back to the LoginViewController so I'm trying to hide the back button in the HomeViewController using:

public override void ViewWillAppear(bool animated)
{
    NavigationItem.SetHidesBackButton(true, false);
} 

Doing this hides the button on the HomeViewController as expected, however when I navigate to any other VC's the Back button is still hidden but tappable because I can tap where the button would be and it would navigate back to the HomeVC. If I then navigate again to the same VC as before, the Back button is visible. So basically it's only hidden on the first load.

Any ideas?

empo
  • 1,133
  • 5
  • 21
  • 41

3 Answers3

0

That's because you set SetHidesBackButton in your ViewWillAppear. Copy paste it in your ViewDidLoad(), and it should work just fine.

More Info

Community
  • 1
  • 1
0

Seems problem with rootViewController which you assign and also with navigationController. To avoid this behaviour you should Navigate and assign rootViewController from AppDelegate, also, improve your back button hiding code.

For more help please paste code, Thank You!

AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

     var rootView: MyRootViewController = MyRootViewController()

     if let window = self.window{
            window.rootViewController = rootView
     }

     return true
}

ViewDidLoad

navigationItem.hidesBackButton = true
Ajay Odedra
  • 3
  • 1
  • 2
  • What's the difference between setting the RootViewController in AppDelegate instead of Storyboard? Also you don't really explain what the problem is with my RootViewController/ NavigationController - can you explain in more detail please? – empo Nov 15 '16 at 11:44
  • @empo Yes you can use it from anywhere but, I didn't seen the code so just a suggestion and good way if we could define rootViewController from AppDelegate. Also hiding back button you should use from viewDidLoad. Many Thanks :) – Ajay Odedra Nov 21 '16 at 12:42
0

Don't try to hide the button. Use NavigationController as root. Push login then home and remove login from navigation stack.

Yuri S
  • 5,355
  • 1
  • 15
  • 23