0

I have a little problem with my app.

I am using ECSlidingViewController.

Here's a overview:

enter image description here

On the ViewController.h:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "ECSlidingViewController.h"
#import "MenuViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) UIButton *menuBtn;

@end

On the ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize menuBtn;

- (void)viewDidLoad
{
    [super viewDidLoad];


    self.view.layer.shadowOpacity = 0.75f;
    self.view.layer.shadowRadius = 10.0f;
    self.view.layer.shadowColor = [UIColor blackColor].CGColor;


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


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


    self.menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(20, 27, 25, 21);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"menuButton.png"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];


    [self.view addSubview:self.menuBtn];


}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.view.layer.shadowOpacity = 0.75f;
    self.view.layer.shadowRadius = 10.0f;
    self.view.layer.shadowColor = [UIColor blackColor].CGColor;
    if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
        self.slidingViewController.underLeftViewController  = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
    }

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




- (IBAction)revealMenu:(id)sender
{
    [self.slidingViewController anchorTopViewTo:ECRight];
}

@end

When I click on the button on View Controller, it creates the ECSliding Effect, bringing up the MenuViewController. Inside the MenuViewController, there's another button, which brings up the testeViewController.

On the testeViewController.h and testeViewController.m, I added the exactly same code as in ViewController. But, when I click on the button inside of MenuViewController to bring up the testeViewcController, the app crashes, with this error:

2013-08-04 18:50:16.174 FacttoBraziliPhone1[21477:c07] *** Terminating app due to uncaught         exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x15ad012 0x12bae7e 0x1560b6a 0x1560a20 0x24ea3f 0xd01b 0x2e01c7 0x2e0232 0x2e04da 0x2f78e5 0x2f79cb 0x2f7c76 0x2f7d71 0x2f889b 0x2f8e93 0x2f8a88 0x654e63 0x646b99 0x646c14 0x12ce705 0x2022c0 0x202258 0x2c3021 0x2c357f 0x2c26e8 0x231cef 0x231f02 0x20fd4a 0x201698 0x260fdf9 0x260fad0 0x1522bf5 0x1522962 0x1553bb6 0x1552f44 0x1552e1b 0x260e7e3 0x260e668 0x1feffc 0x284d 0x2775)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

If ViewController is supposed to be equal to testeViewController, why do I have this crash? Any ideas?

Thanks!

Adrian P
  • 6,479
  • 4
  • 38
  • 55
  • Add a breakpoint in revealMenu. See if you can tell if self.slidingviewcontroller is pointing to anything. – Andrew Aug 04 '13 at 22:28
  • You are trying to add a `nil` object to an array somewhere. Set a symbolic breakpoint and find the line where this is happening. – danielbeard Aug 04 '13 at 22:47
  • I added the breakpoint on revealMenu, but this is not the problem. So I tried to add the breakpoint on [self.view addGestureRecognizer:self.slidingViewController.panGesture]; And guess what? It is the problem. I tried to remove [self.view addGestureRecognizer:self.slidingViewController.panGesture]; and I could open the testeViewController, but the revealMenu did not work! Oh my God, what the heck is going on? :s – Fernando Augusto Marins Aug 04 '13 at 23:07
  • It's definitely [self.view addGestureRecognizer:self.slidingViewController.panGesture]; I added a NSLog before it, and it got executed. I put it after, and it did not get executed. Any ideas on why this simple code is crashing my app? – Fernando Augusto Marins Aug 04 '13 at 23:50
  • @FernandoAugustoMarins In the IF just before the gesture add self.slidingViewController.panGesture.cancelsTouchesInView = NO; it is the only thing I can see that is different, probably will not help. – Recycled Steel Oct 15 '13 at 13:42
  • for me self.slidingViewController is giving me nil. For me Thats the reason for crash – Qamar Suleiman Dec 02 '13 at 18:15

1 Answers1

0

This might have been a problem with ECSlidingViewController. I would upgrade to at least version 1.0.1.

Michael Enriquez
  • 2,520
  • 21
  • 13