0

I have the following to add a custom image as a back button. The problem is that it overrides the default navigation controller back method.

How can I correct this?

 UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"button-back-arrow.png"] forState:UIControlStateNormal];
//[button addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(280, 25, 40, 29)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

thanks for any help

hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • chk my answer http://stackoverflow.com/questions/13488710/how-to-set-a-picture-programmatically-in-a-navbar/13488781#13488781 – Rajneesh071 Dec 04 '12 at 14:40

2 Answers2

1

just add this line and method..

[button addTarget:self 
                       action:@selector(BtnBack_Clicked:)
             forControlEvents:UIControlEventTouchDown];

and call this method

-(IBAction)BtnBack_Clicked:(id)sender{

    [self.navigationController popViewControllerAnimated:YES];
}
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
0
UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 84, 31)];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 84, 31);
[btn setBackgroundImage:[UIImage imageNamed:@"yourImage.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
[btnView addSubview:btn];
self.navigationItem.leftBarButtonItem   = [[UIBarButtonItem alloc] initWithCustomView:btnView];
[btnView release];
iOSDev1987
  • 110
  • 7