//自定义的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,并实现点击事件的响应处理。通过将UIButton添加到cell的accessoryView中,并为按钮注册点击事件,可以在点击按钮时获取当前被点击单元格的indexPath。
137

被折叠的 条评论
为什么被折叠?



