1

I am trying to implement ECSlidingViewController & I am using segues in my storyboards. I am having a problem where the MainViewController's viewDidLoad is being called twice and

self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];

is always getting set to null. More information.

  1. LogIn Screen ( InitViewController ) ------through segue---------> MainViewController.

In my MainViewController I have the following code.

-(void)addMenuViewControllerWithGesture{
self.view.layer.shadowOpacity = 0.075f;
self.view.layer.shadowRadius = 10.0f; 
self.view.layer.shadowColor = [UIColor blackColor].CGColor;
if (![self.slidingViewController.underLeftViewController isKindOfClass:[rsMenuViewController class]]) {

self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
}

In My InitViewController (LogIn)

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

MainViewController *controller = segue.destinationViewController;

// setting some values before going to the next view.

controller.id = 0;

controller.name = @"harish";

self.topViewController = controller;

}

By doing this, the MainViewController's viewDidLoad is getting called twice and the below value is always set to null.

self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];

Hope it's clear. I am kind of stuck here and looking for a solution.

Thanks

Harish
  • 1,469
  • 16
  • 43

1 Answers1

1

Okay, I figured it out. After a long, arduous experience, I figured it out. I asked a similar question here: iOS Adding Menu Causes Crash When Not First View and eventually answered it. I just recently came upon your question.

So let's say you have numerous files (.m and .h for each):

InitViewController

MenuViewController

MainViewController

SpeakersView

The objective was to switch from MainViewController using a button not on the slide menu to SpeakersView, but doing it directly caused the slide menu to be null, as was pointed out by Phillip Mills.

Instead, I put this in InitViewController.h, right underneath @Interface:

@property (nonatomic, retain) NSString *location;

Then this under @implementation in InitViewController.m:

@synthesize location;

I originally had this under ViewDidLoad in InitViewController.m:

self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Main"];

I changed it to this:

if([location length] == 0){location = @"Main";}
self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:location];

That way if the variable was empty, it defaulted to @"Main".

Then in MainView.m, where I execute the code after pressing the button, I have this:

InitViewController *ini;
ini = [self.storyboard instantiateViewControllerWithIdentifier:@"Init"];
ini.location = @"Speakers";

And voilĂ , the view switches just fine to Speakers. More accurately, it switches to InitViewController which automatically switches to Speakers or whatever I set location to.

Hopefully this helps you.

Any questions, let me know.

Community
  • 1
  • 1
Marcel Marino
  • 962
  • 3
  • 17
  • 34