Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Bar Button Item to Left of Navigation Item

I am following this tutorial on adding a sidebar navigation to an app.

In the given source code they have provided the storyboard layouts pre-defined. One of them is a view that has a "Navigation Item" and a "Bar Button Item" which appears on the left of the top navigation bar.

I am trying to do the same in my app, however the button item keeps automatically appearing on the right, and I cannot find any way to move it to the left.

I noticed, in the example provided in the tutorial, it gives this outlet option leftBarButton option:

enter image description here

And when I check mine, it looks like this:

enter image description here

There is no navigation controller because of how SWRevealView works. When I run the app, I can see the button and it works perfectly, only issue is it's on the right hand side. I've compared my view with the example, and cannot seem to find any difference.

Any help is appreciated.

EDIT This might help. In storyboards, this is what the working example looks like:

enter image description here

And this is what mine looks like

enter image description here

like image 778
LondonAppDev Avatar asked Mar 22 '14 18:03

LondonAppDev


2 Answers

Drag BarButtonItem and place left side on your navigation item.

like image 87
Amit Avatar answered Oct 02 '22 13:10

Amit


You can also add left hand side buttons by code:

NSMutableArray *leftBtns = [[NSMutableArray alloc] init];

UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"LeftButton"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonPressed)];
[leftBtns addObject:leftBtn];

[self.navigationItem setLeftBarButtonItems:leftBtns animated:NO];

// method

-(void)leftButtonPressed
{
    NSLog(@"Left Button Tapped");
}
like image 32
David Douglas Avatar answered Oct 02 '22 14:10

David Douglas