Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否将方法添加到UINavigationBar后退按钮?_Ios_Objective C_Uinavigationcontroller_Back Button - Fatal编程技术网

Ios 是否将方法添加到UINavigationBar后退按钮?

Ios 是否将方法添加到UINavigationBar后退按钮?,ios,objective-c,uinavigationcontroller,back-button,Ios,Objective C,Uinavigationcontroller,Back Button,如何将方法添加到UINavigationbar后退按钮,以便每当单击该后退按钮时,都需要检查一些值并显示UIAlertView?这有什么选择吗 我试过这个方法,但对我有效 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

如何将方法添加到UINavigationbar后退按钮,以便每当单击该后退按钮时,都需要检查一些值并显示UIAlertView?这有什么选择吗

我试过这个方法,但对我有效

  - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
    {
    //show alert 
    }
还有这个方法,但都不管用

-(void) viewWillDisappear:(BOOL)animated {
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        // back button was pressed.  We know this is true because self is no longer
        // in the navigation stack.
         NSLog(@"hi");
    }
是的,你可以 越洋

UIBarButtonItem * backBtn = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBackToAllPets:)];

    self.navigationItem.leftBarButtonItem = backBtn;
编写以下函数以检查条件

-(void)goBackToAllPets:(id)sender
{
    if(/*check condition*/)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"message" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        alert.tag = 0;
        [alert show];


    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }


}
是的,你可以 越洋

UIBarButtonItem * backBtn = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBackToAllPets:)];

    self.navigationItem.leftBarButtonItem = backBtn;
编写以下函数以检查条件

-(void)goBackToAllPets:(id)sender
{
    if(/*check condition*/)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"message" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        alert.tag = 0;
        [alert show];


    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }


}

假设您有两个控制器-控制器1和控制器2。 控制器2从控制器1推出。因此,在从控制器1推导航控制器上的控制器2之前

Controller2 *controller2 = [[[Controller2 alloc]  init]autorelease];
self.navigationItem.hidesBackButton = YES;   
现在,在Controller2的viewDidLoad:method中,添加以下代码段

UIBarButtonItem *backBarButtonItem =[[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBackToAllPets:)]autorelease];
self.navigationItem.leftBarButtonItem = backBarButtonItem;

在backButtonClicked方法中,您可以执行想要执行的检查。

假设您有两个控制器—Controller1和Controller2。 控制器2从控制器1推出。因此,在从控制器1推导航控制器上的控制器2之前

Controller2 *controller2 = [[[Controller2 alloc]  init]autorelease];
self.navigationItem.hidesBackButton = YES;   
现在,在Controller2的viewDidLoad:method中,添加以下代码段

UIBarButtonItem *backBarButtonItem =[[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBackToAllPets:)]autorelease];
self.navigationItem.leftBarButtonItem = backBarButtonItem;

在backButtonClicked方法中,您可以执行您想要的检查。

明确地说……现在,我将它添加到我的序言中,告诉我当我快速单击“后退”按钮时,是否有任何问题我收到了发送到解除分配实例0xC102800的错误[myclass name respondsToSelector]消息将您的-(void)goBackToAllPets:(id)问题中的发件人方法代码iOS7+的更改:
uibarbuttonimStyleBordered
uibarbuttonim
的定义中不推荐使用-您必须使用
uibarbuttonimStylePlain
。明确地说……现在我正在将它添加到我的问题中,当我快速单击“上一步”按钮时,我知道是否有任何问题,我遇到了这个错误[myclass name respondsToSelector]发送到解除分配实例0xC102800的消息将您的-(void)goBackToAllPets:(id)问题中的发件人方法代码为iOS7+更改:
uiBarButtonimStyleBorded
uiBarButtonimStyle
的定义中不推荐使用–您必须使用
uiBarButtonimStylePlain