0

我以编程方式将我的选择器视图添加到我的主视图中。如果我触摸选择器视图,它会触摸测试滚动而不是选择器视图,因此我无法从选择器视图中选择一行。

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    viewForValueForPicker = [[UIView alloc]initWithFrame:CGRectMake(125, txtvisitReason.frame.origin.y+txtvisitReason.frame.size.height, 180, 160)];
    UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(125, 0, 180, 30)];
    toolBar.barStyle = UIBarStyleBlackOpaque;
    UIBarButtonItem *btn = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBtnPressToGetValue)]autorelease];
    [toolBar setItems:[NSArray arrayWithObject:btn]];
    [viewForValueForPicker addSubview:toolBar];

    pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(125, 30, 180, 140)];
    pickerView.delegate=self;
    pickerView.dataSource=self;
    pickerView.showsSelectionIndicator=YES;
    [viewForValueForPicker addSubview:pickerView];
    [testscroll addSubview:viewForValueForPicker];// test scroll is my scroll view object i added scroll view to main view 
    [txtvisitReason resignFirstResponder];

}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
   if(touch.view==testscroll){
        viewForValueForPicker.hidden=YES;
        return YES; //If its the main view accept the touch
   }    else
   return NO; //Otherwise(say tableview) don't consume the touch.

}

我在这里实现了 Tapgesture 委托方法,即使我触摸选择器视图,它也会显示主视图。如果触摸选择器视图 touch.view 显示测试滚动并且我的选择器消失。

4

0 回答 0