Home:ALL Converter>How to correctly align rightBarButtonItem after dismissing a modal view controller?

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

Ask Time:2013-11-16T08:57:28         Author:Pwner

Json Formatter

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];

Author:Pwner,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20013266/how-to-correctly-align-rightbarbuttonitem-after-dismissing-a-modal-view-controll
rdelmar :

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).",
2013-11-16T01:20:14
Pagly :

you don't need to use initWithTitle: @ \"\"\n\ntry this:\n\nUIBarButtonItem *editBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@\"myImage\"] style:UIBarButtonItemStyleDone target:self action:@selector(myAction:)];\n\nself.navigationItem.rightBarButtonItems = @[editBarButton];\n",
2014-06-05T10:49:12
yy