2

在 Storyboards 之间的过渡中生成 NavigationBar。如何为 BackNaviItem 分配 onClick 功能?

谢谢


导航栏已自动生成。

我是这样写的。

[[self.navigationItem backBarButtonItem] action:@selector(backNaviItemSenderEvent) forControlEvents:UiControlEvenTouchUpInside];

不工作。(

4

2 回答 2

1

您可以将需要执行的任何代码放在viewWillDisappear正在关闭的视图控制器的后退操作中。

或者,您可以navigationItem.leftBarButtonItem使用例如保存按钮设置 ,并将其链接到您的VC. 后退按钮仅在leftBarButtonItem为时显示nil

于 2012-12-17T09:39:43.010 回答
0

只需在 上添加此自定义按钮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...
}
于 2012-12-17T09:45:06.143 回答