0

我有以下添加自定义图像作为后退按钮。问题是它覆盖了默认的导航控制器返回方法。

我该如何纠正?

 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];

谢谢你的帮助

4

2 回答 2

1

只需添加这一行和方法..

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

并调用此方法

-(IBAction)BtnBack_Clicked:(id)sender{

    [self.navigationController popViewControllerAnimated:YES];
}
于 2012-12-04T12:50:48.847 回答
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];
于 2012-12-04T12:55:51.510 回答