1

UINavigationコントローラーで前のビューではなく、前のビューに移動するにはどうすればよいですか。基本的には、デフォルトの場所ではなく、2つの場所にジャンプして戻したいと思います。

これは確かに型破りですが、今はそれを行う必要があります。

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

助けてくれてありがとう。

4

5 に答える 5

4

セットする:

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];
}
于 2012-06-21T11:04:51.453 に答える
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];
于 2012-06-21T11:02:00.673 に答える
1
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(youractonEvent:] autorelease];
于 2012-06-21T11:02:19.363 に答える
1

If you do not want to depend on array's index then you can do some thing like below :

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];
于 2012-06-21T11:06:30.917 に答える
1

If you have three view controllers in NavigationController and currently you are viewing 3rd view controller and if you want to jump to 1st viewcontroller.

Try this. This will navigate you twice back.

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

Set appropriate value instead of 0 in your case.

于 2012-06-21T11:08:45.913 に答える