Search code examples
ioscocoa-touchios7uinavigationbaruibarbuttonitem

How to correctly align rightBarButtonItem after dismissing a modal view controller?


Beginning in iOS 7, the rightBarButtonItem in my UINavigationBar gets shifted down after dismissing a modal view controller. The top screen shot shows the correct alignment. The bottom screenshot shows the wrong alignment after dismissing the modal view controller.

enter image description here

- (void) viewDidLoad
{
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 
        initWithTitle:@"" 
        style:UIBarButtonItemStyleDone 
        target:self
        action:@selector(didPressRightBarButtonItem)
    ];
    [self.navigationItem.rightBarButtonItem 
        setImage:[UIImage imageNamed:@"shareLightFlat"]
    ];
}

- (void) didPressRightBarButtonItem
{
    [self.navigationController 
        presentViewController:[[SomePage alloc] init] 
        animated:YES 
        completion:nil];
}

In SomePage, I use this to dismiss itself:

[self dismissViewControllerAnimated:YES completion:nil];

Solution

  • I have no idea why this is happening, but when I tested this, it worked ok if I changed the title of the button from @"" to @" ". See if that works for you (I got somewhat different results from you -- my button was always misplaced, not only after the presentation and dismissal).