iOS:我添加的第二个UITapGestureRecognizer不起作用

时间:2014-04-09 11:15:55

标签: ios objective-c uitapgesturerecognizer

我有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吗?

如果是这样,我怎么知道方法中哪个视图被点击了?

0 个答案:

没有答案