UITableCell中的自定义UIButton

//自定义的Cell中定义一个UIButton

UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];

button.frame = CGRectMake(0.0,0.0,image.size.width,image.size.height);

button.backgroundColor =[UIColor clearColor];

[button addTarget:self action:@selector(btnClicked:event:) forControlEvents:UIControlEventTouchUpInside];

cell.accessoryView = button;


//UIbutton的响应事件

-(void)btnClicked:(id)sender event:(id)event

{

    NSSet*touches =[event allTouches];

    UITouch*touch =[touches anyObject];

    CGPoint currentTouchPosition =[touch locationInView:self.tableView];

    NSIndexPath*indexPath =[self.zffsView indexPathForRowAtPoint:currentTouchPosition];

    if(indexPath !=nil)

    {

        [self tableView:self.tableView accessoryButtonTappedForRowWithIndexPath:indexPath];

        //获取button所在的行

int i = indexPath.row;

    }

}

你可能感兴趣的:(UITableViewCell,UIButton)