tableView手势 监听

来源:互联网 发布:sql注入防御 编辑:程序博客网 时间:2024/06/05 18:04

有些时候在使用tableviewcell的时候,我们某一行也许是输入框,另一行也许是普通cell,所以在使用时,需要退下键盘时,我们会给tableview添加手势:

//添加点击手势

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapClick)];

    tapGesture.numberOfTapsRequired =1;

    tapGesture.delegate = self;

    [tableView addGestureRecognizer:tapGesture];


-(void)tapClick{

    [self.viewendEditing:YES];

}


当选择另一行普通cell时需要跳转到另一个viewController时,需要利用手势代理来判断手势

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

    // 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件

    if ([NSStringFromClass([touch.viewclass])isEqualToString:@"UITableViewCellContentView"]) {

        return NO;

    }

    return  YES;

}

这样就可以了

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    UIViewController *nextVC = [UIViewControllernew];

    [self.navigationControllerpushViewController:nextVCanimated:YES];

}



0 0
原创粉丝点击