我创建了一个用于注册的scrollview。我还使用tableview进行下拉(男/女)并在scrollview上点击Gesture以隐藏所有输入视图,因为touchesBegan方法不会调用。每当我点击表视图单元格时,它都不会调用didselect方法,而是考虑在scrollview上点击。
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
tap.numberOfTapsRequired=1;
[_scrollview_out addGestureRecognizer:tap];
方法: -
-(void)dismissKeyboard
{
[_txt_name resignFirstResponder];
[_txt_mname resignFirstResponder];
[_txt_surname resignFirstResponder];
[_txt_gender resignFirstResponder];
[_txt_dob resignFirstResponder];
_tbl_view_gender.hidden=true;
_txt_dob.hidden=false;
_lbl_dob.hidden=false;
}
表视图didSelect方法: -
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_scrollview_out endEditing:YES];
str2=[gender_arr objectAtIndex:indexPath.row];
_txt_gender.text=str2;
_tbl_view_gender.hidden=true;
_txt_dob.hidden=false;
_lbl_dob.hidden=false;
}
答案 0 :(得分:2)
对我来说有两种选择:
1:在tableview
的{{1}}
scrollView
2:子类superView
,覆盖方法:
UIScrollView
答案 1 :(得分:1)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isDescendantOfView:Your Tableview]]) {
// Don't let selections of auto-complete entries fire the
// gesture recognizer
return NO;
}
return YES;
}