如何让导航栏后退按钮返回到另一个视图控制器

How to get a uinavigation bar back button to return to anthother view controller(如何让导航栏后退按钮返回到另一个视图控制器)

本文介绍了如何让导航栏后退按钮返回到另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 UINavigation 控制器导航到前一个视图而不是前一个视图.基本上我希望它跳回 2 个位置而不是默认位置.

How would I go about having a UINavigation controller navigate not to the previous view but the view before that. Basically I would like it to jump back 2 places instead of the default one.

我敢肯定,这是非常规的,但我现在只需要这样做.

This is unconventional I'm sure, but I just need to do it for now.

 self.navigationItem.backBarButtonItem =
    [[[UIBarButtonItem alloc] initWithTitle:@"Back"
                                      style:UIBarButtonItemStyleBordered
                                     target:nil
                                     action:nil] autorelease];

感谢您的帮助.

推荐答案

设置:

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

然后创建一个方法-goBack

-(void)goBack
{
   UIViewController *ctrl = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 2];
   [self.navigationController popToViewController:ctrl animated:YES];
}

这篇关于如何让导航栏后退按钮返回到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何让导航栏后退按钮返回到另一个视图控制器