如何获得uinavigation栏后退按钮返回到anthother视图控制器(How to get

2019-06-25 16:07发布

我怎么会去有UINavigation控制器导航不是以前的看法,但在这之前的观点。 基本上我想它跳回2米的地方,而不是默认的一个。

这是非常规的我知道,但我需要做的仅仅是现在。

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

谢谢你的帮助。

Answer 1:

组:

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];
}


Answer 2:

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


Answer 3:

如果你不希望依赖于数组的索引,那么你可以像下面的一些事情:

MyController * aMyController = nil ;
for (int i=0; i<[[self.navigationController viewControllers] count]; i++) 
{
    NSLog(@"%@",[[self.navigationController viewControllers] objectAtIndex:i]);
    if ([[[self.navigationController viewControllers] objectAtIndex:i] isKindOfClass:[MyController class]]) 
    {
        aMyController = [[self.navigationController viewControllers] objectAtIndex:i];      
    }
}           
[self.navigationController popToViewController:aMyController animated:YES];


Answer 4:

如果您有NavigationController三个视图控制器和当前正在查看3日视图控制器,如果你想跳到第一个视图控制器。

试试这个。 这将引导您回来两次。

[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:0] animated:YES];

设置适当的值,而不是0,你的情况。



Answer 5:

目标添加到您添加的按钮

然后使用下面的代码返回大于1的viewController

//Get the view controller that is 2 step behind
UIViewController *controller = [nav.viewControllers objectAtIndex:nav.viewControllers.count - 2];

//Go to that controller
[nav popToViewController:controller animated:YES];


文章来源: How to get a uinavigation bar back button to return to anthother view controller