このカスタムボタンをに追加しUINavigationBar
、BackButtonにこのボタンをオーバーライドするだけで、クリックイベントで任意のアクションを実行できます。試してみてください。
- (void)viewDidLoad
{
///write your code
UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
//[backbutton setImage:backButtonImage forState:UIControlStateNormal];//this line for set only image on button
[backbutton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
[backbutton setTitle:@"Back" forState:UIControlStateNormal];
backbutton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
UIBarButtonItem * back = [[UIBarButtonItem alloc] initWithCustomView:backbutton];
[backbutton addTarget:self action:@selector(yourButton_Clicked) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = back;
}
そして、この左ボタンをクリックすると、以下のメソッドが呼び出されます...
-(void)yourButton_Clicked{
///Write your code here...
}