在我的表格视图中,我在每个单元格中都有一个按钮
UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
editButton.frame = CGRectMake(281,0, 20, 50);
UIImage *editButtonImage = [UIImage imageNamed:@"edit.png"];
[editButton setImage:editButtonImage forState:UIControlStateNormal];
[editButton setBackgroundColor:[UIColor clearColor]];
[editButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[editButton addTarget:self action:@selector(editButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:editButton];
按钮动作是这个
-(IBAction)editButtonAction:(id)sender{
UIButton *btn = (UIButton*) sender;
UITableViewCell *cell = (UITableViewCell*) btn.superview.superview;
NSIndexPath *indexPath =[self.table indexPathForCell:cell];
int row = indexPath.row;
NSLog(@"Selected row is: %d",row);
}
当我在表格视图中单击按钮时,所选行总是给出 0 知道吗?和任何代码