开发者社区> 问答> 正文

得知UIImageView中那个cell被点击

请问,我创建了tableView,用到自定义单元,用图片定义复选框(UIImageView),如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"cellIdentifier";
    StandardCellWithImage *cell = (StandardCellWithImage *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil) {
        cell = [[StandardCellWithImage alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    }

    cell.checkbox.tag = indexPath.row;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSelectedImageAtIndexPath:)];
    tapGesture.numberOfTapsRequired = 1;
    tapGesture.delegate = self;
    [cell.checkbox addGestureRecognizer:tapGesture];
    cell.checkbox.userInteractionEnabled = YES;

    return cell;
}


在didSelectedImageAtIndexPath方法中:
- (void) didSelectedImageAtIndexPath:(id) sender {
    UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:gesture.view.tag inSection:0];
}

目前我只能知道用户点击了哪行,我想知道用户点击的具体位置,不知道应该怎么实现?

展开
收起
爵霸 2016-03-26 09:04:40 1997 0
1 条回答
写回答
取消 提交回答
  • 两种方式,看你的tableView是哪种样式。 如果是UITableViewStylePlain,你可以将UITableViewCell的separator设置为UITableViewCellSeparatorStyleNone。将tableViewCell的背景色,contentView的背景色设置为透明,在contentView中添加一个UIImag.

    答案来源于网络

    2019-09-30 14:33:08
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载