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

来源:互联网 发布:淘宝快递助手在哪 编辑:程序博客网 时间:2024/06/05 04:45


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

{

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

  UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(TapGestureRecognizer:)];

    [cell addGestureRecognizer:tap];


}   

下面是实现方法

-(void)TapGestureRecognizer:(UITapGestureRecognizer *)sender

{

    

  //  240,20 , 25,25

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

    if ([(UITapGestureRecognizer *)senderstate] == UIGestureRecognizerStateRecognized)

    {

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

        CGPoint point = [(UITapGestureRecognizer *)senderlocationInView: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 = [_dataArrayobjectAtIndex:aIndexPath.row];

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

            [flbecomeFirstResponder];

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

        }

    }

    

}


0 0