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");
}