我有2个UIPickerViews作为文本字段的InputViews。我想检测两者上的点击事件。但是只检测到第一个上的水龙头。
以下是我在ViewDidLoad中的代码:
// for Behandler selection
_behandlerArray = [self fetchBehandler];
_behandlerPickerView = [[UIPickerView alloc] init];
_behandlerTextField.inputView = _behandlerPickerView;
_behandlerPickerView.dataSource = self;
_behandlerPickerView.delegate = self;
[_behandlerPickerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(behandlerPickerTapped:)]];
// for Medikamente selection
_medikamenteArray = [self fetchMedikamente];
_medikamentePickerView = [[UIPickerView alloc] init];
_medikamenteTextField.inputView = _medikamentePickerView;
_medikamentePickerView.dataSource = self;
_medikamentePickerView.delegate = self;
[_medikamentePickerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(medikamentePickerTapped:)]];
以下是方法:
-(void)behandlerPickerTapped:(UIGestureRecognizer *)gestureRecognizer{
NSLog(@"_behandlerPickerView tapped");
}
-(void)medikamentePickerTapped:(UIGestureRecognizer *)gestureRecognizer{
NSLog(@"_medikamentePickerView tapped");
}
但只检测/记录_behandlerPickerView
上的水龙头。
我可以只添加一个UITapGestureRecognizer吗?
如果是这样,我怎么知道方法中哪个视图被点击了?