Reputation: 1473
Little Background :-
I have two storyboards in my project (one with autolayout and one without autolayout). 'Main'
storyboard contains ECSlidingViewController
where I set topviewcontroller
as mentioned on the ECSliding
github page like below:-
My Code:-
-(void)GoToNewStoryBoard
{
UIStoryboard *storyboardWithAutolayout = [UIStoryboard storyboardWithName:@"AutolayoutBoard" bundle:nil];
self.slidingViewController.topViewController = [storyboardWithAutolayout instantiateViewControllerWithIdentifier:@"ViewControllerinNewStoryBoard"];
}
-(void)someMethodInNewViewController
{
ECSlidingViewController *sliding_viewController = (ECSlidingViewController*)[self.navigationController visibleViewController];
if([sliding_viewController isKindOfClass:[ECSlidingViewController class]])
{
MenuViewController *menu = (MenuViewController *)sliding_viewController.underLeftViewController;
NSString *windowType = [[NSUserDefaults standardUserDefaults] valueForKeyPath:@"menuWindowType"];
if([windowType isEqualToString:@"Push_PaymentPage"])
{
[menu pushToViewController];
}
}
}
-(void)pushToViewControllerInNewStoryBoard
{
self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NewVCNav"];
[self.slidingViewController resetTopViewAnimated:YES];
}
Problem:-
How do I get the instance of ECSlidingViewController
in View controller class in new storyboard as [self.navigationController visibleViewController]
gives me instance of UIViewController
class instead of ECSlidingViewController
.
Upvotes: 0
Views: 192
Reputation: 1473
Instead of [self.navigationController visibleViewController]
i used self.slidingViewController.underLeftViewController
as follows:-
-(void)someMethodInNewViewController
{
MenuViewController *menu = (MenuViewController*) self.slidingViewController.underLeftViewController;
[menu pushToAcceptedMember];
}
This gave me the ECSlidingViewController
instance.
Upvotes: 0
Reputation: 16864
You need to create the object into AppDelegate.m
file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboardWithAutolayout = [UIStoryboard storyboardWithName:@"AutolayoutBoard" bundle:nil];
self.slidingViewController = = (ECSlidingViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"ECSlidingVctrID"];
self.slidingViewController.topViewController = [storyboardWithAutolayout instantiateViewControllerWithIdentifier:@"ViewControllerinNewStoryBoard"];
return YES;
}
Create one more method into the AppDelegate.m
file.
-(void)changeViewControllerIntoSlider:(UIViewController*)vc{
self.slidingViewController.topViewController = [storyboardWithAutolayout instantiateViewControllerWithIdentifier:@"ViewControllerinNewStoryBoard"];
}
Now you can access those method and object of ECSlidingViewController
.
Import AppDelegate file into your controller.
#import "AppDelegate.h"
Then Access appDelegate Object. AppDelegate appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDel slidingViewController]//Now you got the reference of slider you can do any thing.
Then Access appDelegate method.
AppDelegate appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDel changeViewControllerIntoSlider:"Your view controller according storyboard"]
Upvotes: 2