0

Hi I don't have an array in this view controller but I am getting an error and when I visit this page first it runs fine but at my last page when I want to add an item I am coming back to this page using segue

Note:1. When I am visiting this page the first time it goes smoothly no error

my aim is this is the menu page for ordering food and in add cart to add new items I am revisiting this page again and it gives me an error. @

UIImageView *drinki = [[UIImageView alloc] init];

it was unwanted so I removed it and then

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onButtonTapped:)];

At this line, my app terminates

This is my log for error

 2017-06-19 09:01:58.156 Barebones[3337:314954] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason: '***
-[__NSArrayM insertObject:atIndex:]: object cannot be nil'
    *** First throw call stack:
    (   0   CoreFoundation                      0x0000000111207b0b __exceptionPreprocess + 171  1   libobjc.A.dylib                     0x0000000110189141 objc_exception_throw + 48    2   CoreFoundation      
0x000000011113c443 -[__NSArrayM insertObject:atIndex:] + 1603   3  
UIKit                               0x0000000111dd6736
-[UIView(UIViewGestures) addGestureRecognizer:] + 200   4   Barebones                           0x000000010f827cb9 -[CategoryViewController viewDidLoad] + 985

This my .m file

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.title = @"Welcome";

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"background"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.view.backgroundColor = [UIColor colorWithPatternImage:image];

//Left slidebutton
_leftbarbutton.target = self.revealViewController;
_leftbarbutton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

UIImageView *drinki = [[UIImageView alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onButtonTapped:)];
_drinksi.userInteractionEnabled = YES;
[_drinksi addGestureRecognizer:tap];

UIImageView *foodi = [[UIImageView alloc] init];
UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onButtonTapped1:)];
_foodi.userInteractionEnabled = YES;
[_foodi addGestureRecognizer:tap1];

}
- (void)onButtonTapped1:(UITapGestureRecognizer *)gestureRecognizer {

[self performSegueWithIdentifier:@"p2" sender:self];
NSLog(@"it works");
}

- (void)onButtonTapped:(UITapGestureRecognizer *)gestureRecognizer {
//UIImageView *myImage = (UIImageView *)gestureRecognizer.view;


[self performSegueWithIdentifier:@"p2" sender:self];
NSLog(@"it works");
}
garyh
  • 2,782
  • 1
  • 26
  • 28
Akshay
  • 179
  • 1
  • 16
  • have you turn on the breakpoint exception, so if it does crash it will actually (most of the time) point to the line that crashes? – Joshua Jun 19 '17 at 03:46
  • @Joshua which exception??can't get u – Akshay Jun 19 '17 at 03:51
  • there is an option in the breakpoint navigation wherein you can add breakpoint for exceptions. when the app crash it will point you to which file or which line crash (most of the time). given the current issue we dont know which is the one generating an error since you said there is no array in the current controller. – Joshua Jun 19 '17 at 03:54
  • how to add that option ?? – Akshay Jun 19 '17 at 04:05
  • You can check below link it might be useful to you https://stackoverflow.com/a/17802723/5184217 – Rajesh Dharani Jun 19 '17 at 04:14
  • @Joshua it crashes at [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; – Akshay Jun 21 '17 at 04:46

1 Answers1

0

my segue connection was wrong i.e it was given to menu view controller and it should be moved to reveal view controller and I used [self.revealViewController panGestureRecogoniser]; now it works fine!! thank you for ur support!!

Akshay
  • 179
  • 1
  • 16