【问题标题】:UITapGestureRecognizer selector not workingUITapGestureRecognizer 选择器不起作用
【发布时间】:2015-09-30 17:16:40
【问题描述】:

我使用自定义 UITableViewCell 制作 UITableView。 我在我的 UITableViewCell 中放了一个 UITextField,我还将 UITapGestureRecognizer 添加到我的 UITableView 中,当点击任何一个单元格时会得到 CGPoint.y。

!!!我的问题在这里!!! 当我专注于任何单元格中的 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;
}

【问题讨论】:

    标签: objective-c uitableview uitextfield uitapgesturerecognizer


    【解决方案1】:

    除非您设置了属性 userInteractionEnabled = YES,否则您的 UITextField 不会将触摸传递给 UIGestureRecognizer。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      相关资源
      最近更新 更多