2013-05-17 35 views
0

我正在使用ECSliding,我遇到了這個問題!從普通視圖控制器打開ECSlidingViewController

在我的項目有此文件:

InitViewController(ECSlidingController)

FirstViewController(UIViewController中)

SecondViewController(UIViewController中)

LeftMenuViewController(UIViewController中)

ThirdViewController(UIViewController中)

我用InitView到instatiate我的firstView的俯視圖,滑動到右側打開的LeftMenu。 在LeftMenu中有2個按鈕,一個按鈕加載爲FirstView的俯視圖,第二個按鈕加載SecondView。

在我的第一和SecondView有加載該ThirdView不是作爲俯視圖控制器,但作爲一個新的視圖相同的按鈕:

ThirdViewController *third = [self.storyboard 
instantiateViewControllerWithIdentifier:@"Third"]; 
[self presentViewController:third animated:YES completion:nil]; 

以我ThirdView 2個按鈕,一個鈕加載的firstView,第二一個加載SecondView。 由於ThirdView不是頂視圖,而是另一種視圖,我必須回想一下ECSliding打開我的FirstView或SecondView。 我成功從我ThirdView加載的firstView用我的InitView

InitialSlidingViewController *home = [self.storyboard 
instantiateViewControllerWithIdentifier:@"Init"]; 
[self presentViewController:home animated:YES completion:nil]; 

但我怎麼能加載SecondView從我ThirdView? 我的問題基本上是我如何加載一些使用ECSliding在普通視圖後。

+0

第一,第二和第三個位於頂視圖控制器中的導航控制器中?你想從第三個回到第一個還是第二個? – Wain

+0

@一切都是UIViewController類,只有InitViewController是ECSliding類,沒有導航控制器 – Tortuga

+0

因此,您按下各種按鈕,並且每次都將視圖控制器設置爲ECSliding視圖控制器中的頂視圖控制器?如果問題涉及到該結構的導航,你真的需要更好地解釋結構。 – Wain

回答

1

Third我們想要去滑動視圖控制器和更改頂視圖控制器。你正在用這個代碼做什麼:

InitialSlidingViewController *home = [self.storyboard instantiateViewControllerWithIdentifier:@"Init"]; 
[self presentViewController:home animated:YES completion:nil]; 

正在創建一個全新的滑動視圖控制器來顯示。最終,通過這樣做,您將耗盡內存,因爲您將分配數百個呈現的視圖並且永遠不可見。

所以,我們要做的是給Third屬性:

@property (weak, nonatomic) ECSlidingViewController *slideController; 

我們想呈現Third之前設置該屬性:

ThirdViewController *third = [self.storyboard instantiateViewControllerWithIdentifier:@"Third"]; 
third.slideController = self.slidingViewController; 
[self presentViewController:third animated:YES completion:nil]; 

現在,當按下其中一個按鈕我們可以這樣說:「展示的是什麼?我們可以解僱還是需要改變和解僱?「:

- (void)oneButtonPressed { 
    if ([self.slideController.topViewController isKindOfClass:[SecondViewController class]]) { 
     FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:@"First"]; 
     self.slideController.topViewController = first; 
    } 

    [self dismissViewControllerAnimated:YES]; 
} 

你需要編寫twoButtonPressed相應的方法,你就大功告成

對於新的評論,而不是呈現third,而應該把它變成一個導航控制器和現在。這一點。然後,當你需要出示fourthfifth你只是把它們放入導航控制器,並再次彈出他們關閉。如果需要,您也可以給他們的slideController參考。

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController :third]; 
[self presentViewController:nav animated:YES completion:nil]; 
+0

抱歉再次打擾你!我有一個'FourthViewController'和'FifthViewController'。兩者都使用ECSliding。我需要將'FourthViewController'從一個按鈕加載到'ThirdViewController'中,然後從按鈕加載'FifthViewController'到'FourthViewController'中。我是否需要從我的'FifthViewController'回到我的'FourthViewController',並從我的'FourthViewController'回到我的'FirstViewController'。我怎樣才能做到這一點? – Tortuga

相關問題