0

I want to create a button at the left side of navigation bar whereby after clicking on it, users will be brought into another page. However I could not make it work. Below is my code. Please help!

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)];
Latonia
  • 1
  • 1
  • 4

2 Answers2

3

Try this.

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]
                                initWithTitle:@"Left"
                                style:UIBarButtonItemStyleBordered
                                target:self
                                action:@selector(leftItemAction)];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]
                               initWithTitle:@"Right"
                               style:UIBarButtonItemStyleBordered
                               target:self
                               action:@selector(rightItemAction)];
self.navigationItem.rightBarButtonItem = rightItem;
self.navigationItem.leftBarButtonItem = leftItem;

- (void)leftItemAction
{
...
}

- (void)rightItemAction
{
...
}
Yeheshuah
  • 1,216
  • 1
  • 13
  • 28
1

I have use this code to add save button

UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setBackgroundImage:[UIImage imageNamed:@"save.png"] forState:UIControlStateNormal];
button2.frame = CGRectMake(0, 0, 100, 31);
[button2 addTarget:self action:@selector(onSave:) forControlEvents:UIControlEventTouchUpInside];    
saveButton = [[UIBarButtonItem alloc]initWithCustomView:button2];
self.navigationItem.leftBarButtonItem = saveButton;
alloc_iNit
  • 5,173
  • 2
  • 26
  • 54
Shehzad Bilal
  • 2,535
  • 2
  • 18
  • 27