我想在我的一个ViewController中更改后退按钮的操作。我没有回到先前的视图,而是想在同一个ViewController中执行一个动作。
self.navigationItem.hidesBackButton=NO;
隐藏BackButton但
[self.navigationController.navigationItem.backBarButtonItem setAction:@selector(performBackNav:)];
和
[self.navigationItem.backBarButtonItem setAction:@selector(performBackNav:)];
和以前一样(回到先前的ViewController)。什么都没有改变。
-(void)performBackNav:(id)sender {
//Actions
[self.navigationController popViewControllerAnimated:NO];
}
修改后退按钮按钮操作的任何想法?
答案 0 :(得分:2)
而不是覆盖默认后退按钮的操作方法,而不是创建自定义按钮。这是试试这个
的方式之一{
UIButton *urButton = [UIButton buttonWithType:UIButtonTypeCustom];
urButton.frame = urRequiredFrame;
[urButton setImage:urImage forState:UIControlStateNormal];
[urButton addTarget:self action:@selector(performBackNav:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithCustomView:urButton];
self.navigationItem.leftBarButtonItem=doneButton;
}
-(void)performBackNav:(id)sender {
//Actions
[self.navigationController popViewControllerAnimated:NO];
}