0

私は4つのビューを持っています。

1つ目はrootView、そしてView1View2View3です。
に従って動作していrootView-> View1-> View2-> View3ます。

View1 から View3にジャンプする必要がありますが、 View3 から戻るボタンを使用すると、 View2 にポップします。次のコードを使用する場合

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

View1からView3をプッシュすると、この時点でView3のインデックス値は2になります。

戻るボタンを使用してView3からView2をポップする他の方法はありますか?

4

3 に答える 3

0

で新しいクラスMYViewController : UIViewControllerを作成しますinitWithBackButton:(UIBarButtonItem *)backButton;

@property (nonatomic, strong) UIBarButtonItem *saveBackButton

- (id)initWithBackButton:(UIBarButtonItem *)backButton {

  self = [super init];

  if(self){
      self.saveBackButton = backButton;
  }
  return self;
}

ルートで

3 つのプロパティ vc1、vc2、vc3 を作成します。

作成するときMYViewController

{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, width, height);
    [button addTarget:self action:@selector(iWantToOpenNumber2:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:button];

    self.vc3 = [[MYViewController alloc] initWithBackButton:backItem];
}

- (void)iWantToOpenNumber2:(id)sender {
    [self dismissViewControllerAnimated: YES completion: ^{
       [self presentViewController:self.vc2 animated: YES completion:^{}]; 
    }];

}
于 2013-08-05T13:06:54.730 に答える
0

view1 を view3 にインポートしてから、view1 のインスタンスを作成し、このコードを貼り付けます

UIViewController *view1Reference = [[UIViewController alloc] init];
[self.navigationController popToViewController:view1Reference animated:YES];
于 2013-08-05T09:44:51.850 に答える
0

戻るボタンから。(特定のインデックスの場合)

NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:2] animated:NO];

(前のビュー用)

[self.navigationController popViewControllerAnimated:YES];
于 2013-08-05T10:11:00.947 に答える