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.
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];