3

I have a parent view controller that sets up the navigation bar with a custom back image and a right bar button item. For some reason one individual screen which is pushed by two different controllers doesn't show the back button image until I press it. Then it's there for good. Anyone come across this? Here is my button code being called in view did load.

// In my app delegate 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Setup custom back button
    UIImage *backButton = [UIImage imageNamed:@"backButton"];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButton.size.width, 0, 0)]
                                                          forState:UIControlStateNormal
                                                        barMetrics:UIBarMetricsDefault];

}

// In the parent view controller that all of the others inherit from
- (void)viewDidLoad
{
    [super viewDidLoad];

    // Custom Back Button
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle: @" "
                                   style: UIBarButtonItemStyleBordered
                                   target: nil action: nil];

    [self.navigationItem setBackBarButtonItem: backButton];

}

This works fine on all screens except one no matter which VC it's pushed from. But the one has a hidden image until the button is pressed.

codeetcetera
  • 3,213
  • 4
  • 37
  • 62
  • you are always using push segues, right? no modals? – Can Poyrazoğlu Oct 17 '13 at 22:16
  • Yup. That's what's so weird to me. – codeetcetera Oct 17 '13 at 22:18
  • 1
    Try using `[self.navigationItem setLeftBarButtonItem:backButton];` – Nekak Kinich Oct 17 '13 at 22:20
  • Wouldn't that remove my back functionality. So as it seems it's everything that inherits from this parent class that are effected. But any other controller that I explicitly put this code in is fine. Not sure, I've obviously screwed something up. – codeetcetera Oct 17 '13 at 22:24
  • Actually as it seems in only works for the first screen. All the other screens are fine when I go back. But the first time they show up nothing is there. – codeetcetera Oct 17 '13 at 22:30
  • So apparently setting this up in viewDidLoad doesn't take on the first screen presentation. So basically VC2 isn't showing the back button set by VC1 until the second time the viewWillAppear/viewDidAppear methods are called. – codeetcetera Oct 17 '13 at 23:06
  • And it's only a problem in iOS 7 – codeetcetera Oct 17 '13 at 23:12
  • This appears to be a pretty broad problem. Here is another question about it: http://stackoverflow.com/q/18099073/793607 – HalR Oct 17 '13 at 23:25
  • Yeah, now that I understand what the problem is I'm finding more about it. Not thrilled with the idea of method swizzling and having to implement the back button myself, but I guess it is what it is. – codeetcetera Oct 17 '13 at 23:31
  • 1
    iOS 7-- its not a bug, its a *feature* – HalR Oct 18 '13 at 03:10
  • Are you sure that the back button is in UIControlStateNormal? – Austin Jul 20 '14 at 07:46

0 Answers0