NavigationController更改后退按钮

时间:2013-10-19 10:53:32

标签: ios objective-c ios6 ios7

我有两个问题:

问题1:我正在尝试更改导航后退按钮,我是从我的父ViewController进行的:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"imgrdy"]) {
        VCImageEditingViewController *ieVC = (VCImageEditingViewController *)segue.destinationViewController;
        UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"New" style:UIBarButtonItemStyleBordered target:nil action:@selector(handleNewBtnNav:)];
        [[self navigationItem] setBackBarButtonItem: newBackButton];    
    }
}
-(IBAction)handleNewBtnNav:(id)sender {
    UIAlertView *alertNew = [[UIAlertView alloc]initWithTitle:@"New photo" message:@"Are you sure?" delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
    [alertNew show];
}

标题确实已更改,但未显示警报。我试图将目标改为“自我”和“ieVC”,但仍然没有。

问题2:有没有办法只更改一个ViewController的后退按钮的标题?或者我必须对每个父ViewController进行相同的更改吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

在声明按钮时使用target:self,这是动作的接收者,你说的是nil

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"New" style:UIBarButtonItemStyleBordered target:self action:@selector(handleNewBtnNav:)];