2013-08-05 92 views
0

我有4個觀點。UINavigation Views的後退按鈕動作?

月1日是rootView然後View1View2 & View3
它根據rootView-> View1-> View2-> View3工作。

我不得不跳過從View1到View3但是當我使用View3的後退按鈕時,它會彈出到View2。 如果我使用下面的代碼

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

這是行不通的索引的原因,此時VIEW3具有索引值2,當我從視圖推VIEW3 1.

那麼,有沒有任何其他方法彈出View3使用後退按鈕查看View3?

+0

目前尚不清楚你想要的跳躍,從視圖1至VIEW3需求推動或需求VIEW3坡平彈出視圖2。 –

回答

0

在根

initWithBackButton:(UIBarButtonItem *)backButton;

@property (nonatomic, strong) UIBarButtonItem *saveBackButton 

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

    self = [super init]; 

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

創建新的類MYViewController : UIViewController

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

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

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

你能告訴我,它會做什麼? –

+0

打開View2不帶動畫,View3帶動畫;當你按下後退按鈕view3將被關閉,view2將在窗口 –

+0

抱歉..但它不是我問的東西。因爲我已經告訴過這種方法,它在做什麼,在我的問題上面..無論如何謝謝 –

0

導入在VIEW3的廠景然後創建廠景的實例,並通過回退按鈕粘貼此代碼

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

nope ..它不工作。 –

+0

你在用故事板嗎? – iosLearner

+0

然後使用自定義的後退按鈕,從該按鈕調用一個動作,並在該動作中使用此代碼.. – iosLearner

0

。 (對於特定的索引)

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

(對於前視圖)

[self.navigationController popViewControllerAnimated:YES];