Pressing Right Bar Button Item Moves Left Bar Button Items

懵懂的女人 提交于 2019-12-11 07:17:47

问题


I have three left bar button items on my web view nav bar. One that goes back to the the menu of my app and back and forward buttons. I have one right bar button that opens an activity view controller. When I press the right button, the forward and back buttons on the left get moved down and off of the nav bar.

- (void)viewDidLoad
{   
    leftBarButtonItems = [NSArray arrayWithObjects:@"Menu", @"Back", @"Forward", nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *urlAddress = @"http://www.littleheartrecords.com/releases.html";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];

    UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showMenu)];
    self.navigationItem.rightBarButtonItem = systemAction;

    UIBarButtonItem *openItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStylePlain target:self action:@selector(openButtonPressed)];
    self.navigationItem.leftBarButtonItem = openItem;

    UIImage *back = [UIImage imageNamed:@"back_arrow"];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:@"" style: UIBarButtonItemStylePlain target:self action:@selector(GoBack)];
    [backButton setImage:back];

    UIImage *forward = [UIImage imageNamed:@"forward_arrow"];
    UIBarButtonItem *forwardButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(GoForward)];
    [forwardButton setImage:forward];

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:openItem, backButton, forwardButton, nil];
}


回答1:


Strangely, what worked for me was setting the title of the buttons with images to a single space:

barButtonItem.title = @" ";
barButtonItem.image = [UIImage imageNamed:@"MenuIcon.png"];


来源:https://stackoverflow.com/questions/21311837/pressing-right-bar-button-item-moves-left-bar-button-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!