-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
NSLog(@"touch recognised");
CGPoint location = [aTouch locationInView:_mainView];
__block NSString *option = [[NSString alloc] init];
__block NSString *type = [[NSString alloc] init];
for (Selectors *tempView in _mainView.subviews) {
if (CGRectContainsPoint(tempView.frame, location)) {
NSLog(@"%@ : %@", tempView.option, tempView.type);
option = tempView.option;
type = tempView.type;
break;
}
}
[self moveToNextWeldCustomViewWithOption:option andType:type];
}
在我之前的UIVIewController中 - 然后我们在这里展示下一个UIViewController
-(void)moveToNextWeldCustomViewWithOption:(NSString *)option andType:(NSString *)type {
WeldDesignViewController *lobby = [self.storyboard instantiateViewControllerWithIdentifier:@"WeldDesignViewController"];
lobby.option = option;
lobby.type = type;
[self presentViewController:lobby animated:NO completion:nil];
}
在下一个UIViewController中,我没有做任何事情,直到viewDidAppear方法 - 但是,触摸开始仍然在下一个viewcontroller中被识别。
答案 0 :(得分:2)
我认为问题在于您正在呼叫的VC&#34; lobby&#34;您出示后正在取消分配。这在响应者链中不考虑它。将该引用移动为呈现视图控制器的属性:
@property (nonatomic, strong) WeldDesignViewController* lobby;
// ...
-(void)moveToNextWeldCustomViewWithOption:(NSString *)option andType:(NSString *)type {
self.lobby = [self.storyboard instantiateViewControllerWithIdentifier:@"WeldDesignViewController"];
lobby.option = option;
lobby.type = type;
[self presentViewController:self.lobby animated:NO completion:nil];
}
您可能还需要在显示的VC中实现touchesBagan
,因为它可能跟随前一个控制器的响应者链。