And Then There’s the Bar Button Item

If you build and run the app now, all is well and good except for one thing — because you’re now using a Navigation controller, the text color of the Road Trip button is yellow. (If you remember, you set the default in application:DidFinishLaunchingWithOptions: in Chapter 8.)

Not to worry. In RTDetailViewController splitViewController:willHideViewController:withBarButtonItem: forPopoverController:, you just need to add one line of code to make the Road Trip button text green. Add the code in bold in Listing 16-20 to splitViewController:willHide ViewController:withBarButtonItem:forPopoverController: in RTDetailViewController.m.

Listing 16-20: Keeping the Road Trip Button Color Green

- (void)splitViewController:

(UISplitViewController *)splitController willHideViewController:

(UIViewController *)viewController withBarButtonItem:

(UIBarButtonItem *)barButtonItem forPopoverController:

(UIPopoverController *)popoverController

{

barButtonItem.title =

NSLocalizedString(@”Road Trip”, @”Road Trip”);

[barButtonItem setTitleTextAttributes:

[NSDictionary dictionaryWithObject:[UIColor greenColor] forKey:UITextAttributeTextColor] forState:UIControlStateNormal];

if ([[self.splitViewController.viewControllers lastObject] isKindOfClass:[UINavigationController class]])

[self.navigationItem setLeftBarButtonItem:barButton Item animated:YES];

else {

NSMutableArray *itemsArray =

[self.toolbar.items mutableCopy];

[itemsArray insertObject:barButtonItem ...

Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.