重新访问视图控制器给了我错误

时间:2017-06-19 03:42:12

标签: ios objective-c xcode

嗨我在这个视图控制器中没有数组,但是我收到一个错误,当我访问此页面时它首先运行良好但在我的最后一页当我想要添加项目时我将回到此页面使用segue

注:1。当我第一次访问此页面时,它顺利进行没有错误

我的目标是这是订购食物的菜单页面,并添加购物车添加新项目我再次访问此页面,它给了我一个错误。 @

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

这是不需要的,所以我删除了它然后

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

在这一行,我的应用程序终止

这是我的错误日志

 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

这是我的.m文件

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

1 个答案:

答案 0 :(得分:0)

我的segue连接错误,即它被赋予菜单视图控制器,它应该被移动以显示视图控制器,我使用[self.revealViewController panGestureRecogoniser];现在它工作正常!!谢谢你们的支持!!