1

我使用自定义UITableViewCell制作UITableView。 我把一个UITextField放在我的UITableViewCell中,当我添加UITapGestureRecognizer到我的UITableView时,点击一个任意单元格就可以获得CGPoint.y。UITapGestureRecognizer选择器不工作

!!!我的问题在这里!!! 当我专注于任何单元格中的UITextField时,我的UITapGestureRecognizer选择器不工作 !!!但是当我点击除了UITextField UITapGestureRecognizer选择器工作的单元格的任何地方!

我想在UITextField UITapGestureRecognizer选择器工作时获得焦点并获得屏幕的point.y!

这是我的代码:除非你已经设置的属性

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self.view addSubview:self.prsnTable];  
    UITapGestureRecognizer *tpgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapPress:)]; 
    [self.prsnTable addGestureRecognizer:tpgr]; 

} 
- (void)handleTapPress:(UITapGestureRecognizer*)gestureRecognizer{ 
    CGPoint p = [gestureRecognizer locationInView:self.prsnTable]; 
    NSLog(@"%f",p.y); 
} 
- (UITableView*)prsnTable { 
    if (!_prsnTable) { 
     CGRect tableFrame = CGRectMake(0,0,CGRectGetWidth(self.view.frame),CGRectGetHeight(self.view.frame)-70); 
     _prsnTable =[[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain]; 
     _prsnTable.scrollEnabled = YES; 
     _prsnTable.delegate = self; 
     _prsnTable.dataSource = self; 
     _prsnTable.showsVerticalScrollIndicator = YES; 
     [_prsnTable setBackgroundColor:[UIColor clearColor]]; 
     _prsnTable.separatorStyle = UITableViewCellSeparatorStyleNone; 
     _prsnTable.contentInset = UIEdgeInsetsMake(0,0,0,0); 
    } 
    return _prsnTable; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    SourCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SourCell"]; 
    if (!cell) { 
     cell = [[SourCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SourCell"]; 
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    [cell setBackgroundColor:[UIColor clearColor]]; 
    MFTextField *tfName = (MFTextField*)[cell viewWithTag:11]; 
    tfName.delegate = self; 
    return cell; 
} 

#pragma mark - TextField Delegate 
- (void)textFieldDidBeginEditing:(UITextField *)textField{ 

    NSLog(@"focus"); 
} 
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    NSLog(@"aaaaaa"); 
    return YES; 
} 

回答

0

你的UITextField将无法通过触摸到UIGestureRecognizer userInteractionEnabled = YES。