I'm developing an iPhone application with latest SDK and XCode 4.2
I use a UINavigationController, and to show a new ViewController I do this on AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
}
else
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.viewController.title = NSLocalizedString(@"MAIN", nil);
navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navController.navigationBar.tintColor = [UIColor darkGrayColor];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
- (void) openDocumentation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
docViewController = [[DocumentationViewController alloc] initWithNibName:@"DocumentationViewController_iPhone" bundle:nil];
}
else
{
docViewController = [[DocumentationViewController alloc] initWithNibName:@"DocumentationViewControllerr_iPad" bundle:nil];
}
docViewController.title = NSLocalizedString(@"DOCUMENTATION", nil);
self.viewController.navigationItem.backBarButtonItem.title = @"Back";
[navController pushViewController:docViewController animated:YES];
}
On DocumentationViewController.m
I do this:
- (void) viewWillAppear:(BOOL)animated
{
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
}
But it doesn't change back button title.
I move that code to viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
}
- (void) viewWillAppear:(BOOL)animated
{
}
But still doesn't work.
And this doesn't work either:
- (void) viewWillAppear:(BOOL)animated
{
self.navigationItem.backBarButtonItem.title = @"Back";
}
But if I do this, to test if I can't access back button:
- (void) viewWillAppear:(BOOL)animated
{
self.navigationItem.hidesBackButton = YES;
}
It works!! And hides back button.
What am I doing wrong?