I’m creating an array of view controllers, adding them to a UINavigation Controller, and then presenting them modally.
I cannot however set the text to the “back” button in each view to anything other than the word “back”.
This is the code:
//The View Controllers and Array
VC1 *vc1 = [[VC1 alloc] initWithNibName:@"VC1" bundle:nil];
VC2 *vc2 = [[VC2 alloc] initWithNibName:@"VC2" bundle:nil];
VC3 *vc3 = [[VC3 alloc] initWithNibName:@"VC3" bundle:nil];
NSArray * viewControllers = [NSArray arrayWithObjects:vc3, vc2, vc1, nil];
// Create the nav controller and set the view controllers.
UINavigationController* theNavController = [[UINavigationController alloc]
initWithRootViewController:vc3];
[theNavController setViewControllers:viewControllers animated:NO];
// Display the nav controller modally.
[self presentModalViewController:theNavController animated:YES];
I have tried the following in the init of each VC:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"Acknowledge Briefings Read";
self.navigationItem.backBarButtonItem = barButton;
… but it does not work. Any ideas? Many thanks.
Also, related, I’d ideally like to navigate the stack in a “forwards” direction. Is this possible using a navigation controller?
You can’t do anything view-wise in the init. You need to wait for viewDidLoad (or willAppear or didAppear), since nothing has been drawn in init (in the case of the nav controller, the previous item will be affected).
Here is what I do (in viewDidLoad):