自定义的cell上面点击不同的控件,不同的响应

本文介绍如何在UITableViewCell中添加UITapGestureRecognizer,并通过实例演示了如何利用手势识别来获取cell的相关信息,包括行列索引等。


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

{

//给cell添加手势tap ,longtap都行

  UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapGestureRecognizer:)];

    [cell addGestureRecognizer:tap];


}   

下面是实现方法

-(void)TapGestureRecognizer:(UITapGestureRecognizer *)sender

{

    

  //  240,20 , 25,25

    //添加手势获取cell的信息

    if ([(UITapGestureRecognizer *)sender state] == UIGestureRecognizerStateRecognized)

    {

         NSIndexPath * aIndexPath = [mTableView indexPathForCell:((UITableViewCell *)(sender.view))];

        CGPoint point = [(UITapGestureRecognizer *)sender locationInView:mTableView];

        int a = point.y - tmpheght;

         NSLog(@"point=%f:%d",point.x,a % 150);

        

       // int a =  4%2;

        if (point.x >240.0 && point.x<=265.0 && a % 150>=20.0 &&a % 150<= 45)

        {

            

            aIndexPath = [mTableView indexPathForRowAtPoint:point];

            ChatItem *item = [_dataArray objectAtIndex:aIndexPath.row];

            NSLog(@"zhende jiade a ---------%@",item.UserName);

            [fl becomeFirstResponder];

            fl.text = [NSString stringWithFormat:@"%@说:",item.UserName] ;

        }

    }

    

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值