0

I am using a storyboard to switch between views. Pretty simple, until I try to add ECSlidingViewController.

If I add the above slide menu to the first view I call using this:

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

If I set @"Main" to @"Speakers", the view loads just fine. I get the slide menu and everything. @"Main" also loads just fine.

However, if I load @"Main" first like in the code above, then switch views to the one I've designated "Speakers", it crashes as soon as I try to call the slide menu with this code:

   if(![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
    self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
   }

   [self.view addGestureRecognizer:self.slidingViewController.panGesture];

I get a crash stating: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

I have tried switching views numerous ways.

I've tried:

SpeakersView *second= [self.storyboard instantiateViewControllerWithIdentifier:@"Speakers"];
[self presentViewController:second animated:YES completion:nil];

I've tried:

  SpeakersView *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"Speakers"];

[self presentViewController:svc animated:YES completion:nil];

Each one works just fine if I don't call up the slide menu, but each causes a crash when I do add the slide gesture.

Ideas?

Marcel Marino
  • 962
  • 3
  • 17
  • 34
  • Use `NSLog` to show the value of `self.slidingViewController` and `self.slidingViewController.panGesture` just before the call to `addGestureRecognizer`. What does it show? – Phillip Mills Aug 06 '13 at 22:14
  • @PhillipMills I get the following, respectively to what you asked for: 2013-08-07 10:00:42.341 IndustryForumAppV2[2109:11303] (null) 303311328 2013-08-07 10:00:42.343 IndustryForumAppV2[2109:11303] (null) 303311328 – Marcel Marino Aug 07 '13 at 14:03
  • @PhillipMills This is what I get when I set the class to come out first: 2013-08-07 10:19:53.706 IndustryForumAppV2[2207:11303] 300217184 2013-08-07 10:19:53.708 IndustryForumAppV2[2207:11303] ; target= <(action=updateTopViewHorizontalCenterWithRecognizer:, target=)>> 300217184 – Marcel Marino Aug 07 '13 at 14:20
  • What is the full stack trace of the crash? – BergQuester Aug 07 '13 at 16:41
  • Is your initial view controller in your storyboard an instance of ECSlidingViewController or a subclass of it? – geraldWilliam Aug 07 '13 at 16:45
  • @geraldWilliam A subclass. I was following the directions from here: http://www.youtube.com/watch?v=tJJMyzdB9uI – Marcel Marino Aug 07 '13 at 17:01
  • @BergQuester *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: (0x1ca8012 0x10e5e7e 0x1c5bb6a 0x1c5ba20 0x79a3f 0xbd18 0x10b1c7 0x10b232 0x116c25 0x3163a3 0x113ee3 0x114167 0xb6fe 0x10f9705 0x2d2c0 0x2d258 0xee021 0xee57f 0xed6e8 0x5ccef 0x5cf02 0x3ad4a 0x2c698 0x1c03df9 0x1c03ad0 0x1c1dbf5 0x1c1d962 0x1c4ebb6 0x1c4df44 0x1c4de1b 0x1c027e3 0x1c02668 0x29ffc 0x229d 0x21c5) libc++abi.dylib: terminate called throwing an exception (lldb) – Marcel Marino Aug 07 '13 at 17:02
  • 1
    Unfortunately, that is not symbolicated. Please see http://stackoverflow.com/questions/10878035/how-to-trace-where-xcode-program-crash for how to get a symbolicated stack trace from the debugger. Once you have it in the debugger, you can select the stack frames from the sidebar and copy. – BergQuester Aug 07 '13 at 17:04
  • @BergQuester I added the exception breakpoint. What else was there? I don't see any different output now that it has been added. Thanks for that info btw, I never knew about the exception breakpoint and was wondering why there wasn't something like that. Why it isn't enabled by default is beyond me. – Marcel Marino Aug 07 '13 at 18:04
  • The stack trace for the crash should be in the debugger navigator in the left-hand sidebar. If not, make sure you are running a debug configuration. – BergQuester Aug 07 '13 at 18:30
  • @BergQuester This is where it stopped, is this what you are looking for? 0x10b1c2: calll 0x5b7f06 ; symbol stub for: objc_msgSend 0x10b1c7: movl 7403580(%edi), %eax 0x10b1cd: movl (%esi,%eax), %eax 0x10b1d0: movl 7305152(%edi), %ecx 0x10b1d6: movl %ecx, 4(%esp) 0x10b1da: movl %eax, (%esp) 0x10b1dd: calll 0x5b7f06 ; symbol stub for: objc_msgSend 0x10b1e2: movl 7305512(%edi), %ecx This line is where it stops: 0x10b1c7: movl 7403580(%edi), %eax – Marcel Marino Aug 07 '13 at 18:46
  • I am looking for the stack trace in the sidebar. ie this: http://i.stack.imgur.com/Swcuj.png Assembly code and function addresses aren't terribly helpful, we need method names. :-) – BergQuester Aug 07 '13 at 18:48
  • @BergQuester So you need this?: http://mjmwebstudios.com/screenshot1.png – Marcel Marino Aug 07 '13 at 18:56
  • I'm not sure what you mean by "set the class to come out first" in your second answer to me above. If those objects are null (1st answer), that's your problem. – Phillip Mills Aug 08 '13 at 12:31
  • @PhillipMills What I mean is that in InitViewController, I use the below code to bring up the first view when the app started. self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Main"]; If I put "Speakers" where main is, Speakers and its menu load just perfectly. If I try to switch views from "Main" to speakers with a button on speakers, it works fine unless I call the menu, at which point it crashes. – Marcel Marino Aug 08 '13 at 14:25
  • Apparently (assuming I understand your NSLog output correctly), that's because you don't have a valid `slidingViewController` when you switch. – Phillip Mills Aug 08 '13 at 14:56
  • @PhillipMills Correct. The question is "why" and "how do I fix it". Switching to that view from InitViewController is fine, but not when switching from a different view (which has the menu working). I found this solution, but I don't know how to implement it: you need 3 view controllers (one "manager", one top, and one under). You get this error when you only use 2 view controllers and the manager and top view controller are the same. The manager should instantiate the top, which should instantiate the one under it. (not the manager initiate the top (itself) and then initiate the one under). – Marcel Marino Aug 08 '13 at 15:01

1 Answers1

1

Okay, I figured it out. After a long, arduous experience, I figured it out.

So I've got 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.

Thanks to everyone for your help.

Marcel Marino
  • 962
  • 3
  • 17
  • 34