0

I'm using ECSliding and I have this problem!

In my project there are this files:

InitViewController (ECSlidingController)

FirstViewController (UIViewController)

SecondViewController (UIViewController)

LeftMenuViewController (UIViewController)

ThirdViewController (UIViewController)

I use InitView to instatiate my FirstView as the topview, sliding to right opens the LeftMenu. In the LeftMenu there are 2 buttons, one button loads as topview the FirstView, the second one loads the SecondView.

In my First and SecondView there is an identical button that loads the ThirdView not as topview controller but as a new view:

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

In my ThirdView are 2 buttons, one button loads the FirstView, the second one loads the SecondView. As the ThirdView is not a topview but another view I have to recall ECSliding to open my FirstView or SecondView. I succeeded loading the FirstView from my ThirdView by using my InitView

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

But how can I load the SecondView from my ThirdView? My question basically is how can I load something that use ECSliding after a normal View.

Tortuga
  • 97
  • 3
  • 10
  • First, second and third are in a navigation controller in the top view controller? And you want to go back, from the third to the first or second? – Wain May 17 '13 at 18:44
  • @Wain everything is UIViewController class, only the InitViewController is ECSliding class, there are no navigation controller – Tortuga May 17 '13 at 22:32
  • So you press various buttons and each changes the view controller set as the top view controller in the ECSliding view controller? You really need to explain the structure better if the question relates to navigation of that structure. – Wain May 17 '13 at 22:48
  • @Wain edited! I hope is more understandable now. – Tortuga May 18 '13 at 02:19

1 Answers1

1

From Third we want to go back to the sliding view controller and change the top view controller. What you're currently doing with this code:

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

Is creating an entirely new sliding view controller to show. Eventually, by doing this, you'll run out of memory because you'll have hundreds of presented views allocated and never visible.

So, what we want to do is give Third a property:

@property (weak, nonatomic) ECSlidingViewController *slideController;

And we want to set that property before presenting Third:

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

Now, when one of the buttons is pressed on third we can say: "what's on display? Can we just dismiss or do we need to change and dismiss?":

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

    [self dismissViewControllerAnimated:YES];
}

You need to write the corresponding method for twoButtonPressed and you're done.

For your new comment, rather than presenting the third, instead you should put it into a navigation controller and present that. Then, when you need to present fourth and fifth you just push them into the nav controller and pop them off again. If required you can also give them a reference to the slideController.

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController :third];
[self presentViewController:nav animated:YES completion:nil];
Wain
  • 118,658
  • 15
  • 128
  • 151
  • Sorry to bother you again! I Have a `FourthViewController` and `FifthViewController`. Both use ECSliding. I need to load the `FourthViewController` from a button into `ThirdViewController`, then load `FifthViewController` from a button into `FourthViewController`. Did that I need to go back from my `FifthViewController`to my `FourthViewController`, and from my `FourthViewController` to my my `FirstViewController`. How can I do that? – Tortuga May 20 '13 at 17:21