dclowd9901
dclowd9901

Reputation: 6826

Can't access navigation controller back button

In a detail view of my app, the navigation controller's back button seems to be taking cues for its color from some ungodly manifestation. Via one path to the detail view, it's blue; via another, it's black. In either case, the back button doesn't seem to exist within the self.navigationController object.

So here's a detail view:

detail view of my app

And here's a snapshot of the navigation controller at this point:

enter image description here

I'm pretty sure I know how to change the color of this particular element, but I don't know where to find it. Ideas?

VenueTableViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *show;

    if( [self.listType isEqualToString:@"showsByRegion"] )
    {
        NSString *venueIndex = [[self.allShows allKeys] objectAtIndex:[indexPath indexAtPosition:0]];
        int index = [indexPath indexAtPosition:1];
        show = [[self.allShows objectForKey:venueIndex] objectAtIndex:index];
    } else {
        int index = [indexPath indexAtPosition:(indexPath.length - 1)];
        show = [self.showsAtVenue objectAtIndex:index];
    }

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                                         bundle:[NSBundle mainBundle]];

    detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];

    detailViewController.showInfo = show;

    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];

}

InfoViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView = [[self.view subviews] objectAtIndex:1];

    [self createInfoViewDictionary];
    [self addTopImage];
    [self setFrameForTableView];
    [self bindLabelsToProperties];

    [self.navigationController.navigationBar setTitleTextAttributes:[SHColors sharedInstance].navBarText];
}

Upvotes: 2

Views: 2842

Answers (6)

Alex
Alex

Reputation: 1051

If you are getting different colors is because you are getting there from different viewcontrollers and those viewcontrollers have different tintColor.

Then, you need to set the color you want using:

- (void)viewDidLoad
{
    ....
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    ....
}

If you are thinking in have the same color for all the navigation bar, you can use UIAppearance proxy to set them in AppDelegate (editted: as Jordan Montel said)

Upvotes: 3

Marek R
Marek R

Reputation: 37927

Like @micantox said the back button comes from previous view controller. So if you want to access back button visible for current controller you have to access presenting view controller, so best way to get that is:

self.presentingViewController.navigationItem.backBarButtonItem

Upvotes: 0

Jordan Montel
Jordan Montel

Reputation: 8247

You can set the tintColor of your navigation bar in the method didFinishLaunchingWithOptions on your AppDelegate if you want to change the whole back title color :

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];

The didFinishLaunchingWithOptions method :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
   [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    return YES;
}

Upvotes: 2

Ravi
Ravi

Reputation: 8309

The tintColor property of the views sets the different colors of the back button and is inherited from the superviews if none is set. You can set the tint color for your entire app by doing this in app delegate:

window.tintColor = [UIColor purpleColor];

For your situation, you need to backtrace and see where the individual colors are coming from in each navigation path and set the tintColor property of the navigation bar.

Upvotes: 0

micantox
micantox

Reputation: 5616

The back button on a navigation bar belongs to the view controller that the back button would send you to. i.e.

A --->B --->C

C's back button belongs to B navigation items and B's back button belongs to A navigation items.

This means that you need to check what you do in the previous View Controller.

Upvotes: 3

Moxy
Moxy

Reputation: 4212

Set the tintColor of the navigation controller's navigation bar to whatever color you want the back button to be.

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

On iOS 6 this would set the whole bar to be white.

If you set the tint color of some superview of the navigation bar, then the back button will inherit it if it's not set.

Upvotes: 1

Related Questions