UINavigation Views的后退按钮动作?

时间:2013-08-05 09:30:58

标签: ios objective-c uinavigationcontroller

我有4个观看次数。

第一个是rootView,然后是View1View2& View3
它正在根据rootView-> View1-> View2-> View3工作。

我必须将从View1跳到View3 但是当我使用View3的后退按钮时,它会弹出到View2。 如果我使用以下代码

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

它不起作用索引的原因,此时当我从View 1推送View3时,View3的索引值为2。

那么还有其他方法可以使用后退按钮从View3弹出View2吗?

4 个答案:

答案 0 :(得分:0)

在view3中导入view1,然后为view1创建一个实例并粘贴此代码

UIViewController *view1Reference = [[UIViewController alloc] init];
[self.navigationController popToViewController:view1Reference animated:YES];

答案 1 :(得分:0)

通过后退按钮。 (具体指标)

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

(以前的观点)

[self.navigationController popViewControllerAnimated:YES];

答案 2 :(得分: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;
}

在root

创建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:^{}]; 
    }];

}

答案 3 :(得分:-1)

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];

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