-1

Is it possible to run a method in viewController A which hides the back button in viewController B, but not in viewController C?

Example: View A is a "hidden" screen which only initializes a few things for the app. View B is a web view, and View C is a menu. I would like to remove the Back button from View B by calling a method in View A.

Is this possible without implementing the following in the view controller I am trying to load:

self.navigationItem.hidesBackButton = YES;

Thanks.

Nayan
  • 3,014
  • 2
  • 17
  • 33
Jake Chasan
  • 6,290
  • 9
  • 44
  • 90

1 Answers1

0

Try doing this in viewDidLoad method of each controller

self.navigationItem.hidesBackButton = YES;

But if you want to have this done in OOPS way, then make a baseViewController & subclass other controllers from baseViewController.

Make a method on baseViewController as

-(void)showBackButton:(Bool)show {

     self.navigationItem.hidesBackButton = !show;

}

And call this from viewDidLoad of your base. This will keep back button to the state represented by "show" value. Then wherever you want it to enable or disable, just call in the viewDidLoad of respective controller.

Hope that helps.

Nayan
  • 3,014
  • 2
  • 17
  • 33
Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41