Iphone addTarget:action:forControlEvents:来自UITableViewCell
我有一个带3个复选标记按钮的UITableViewCell。每个复选标记按钮都是一个自定义UIButton(实际上只是图像),并且在自定义UITableViewCell子类中有一个出口。在cellForRowAtIndexPath方法中,我Iphone addTarget:action:forControlEvents:来自UITableViewCell,iphone,Iphone,我有一个带3个复选标记按钮的UITableViewCell。每个复选标记按钮都是一个自定义UIButton(实际上只是图像),并且在自定义UITableViewCell子类中有一个出口。在cellForRowAtIndexPath方法中,我 [cell.firstcheckmark addTarget:self action:@selector(checkmarkPressed:) forControlEvents:UIControlEventTouchUpInside]; [cell.seco
[cell.firstcheckmark addTarget:self action:@selector(checkmarkPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.secondcheckmark addTarget:self action:@selector(checkmarkPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.thirdcheckmark addTarget:self action:@selector(checkmarkPressed:) forControlEvents:UIControlEventTouchUpInside];
- (void)checkmarkPressed:(id)sender {
// how do I get which checkmark was pressed?
}
我不知道如何从发送者对象获取按下的按钮。其他时候,我可以使用按钮的标题,但在这种情况下,所有按钮都是相同的,除了它们的插座。我如何知道按下了哪个按钮?或者他们需要调用不同的方法,然后在这三个方法中的每一个中,我可以通过调用相同的modelUpdateMethod来更新我的模型:从这三个方法中的每一个?谢谢。您可以通过标签识别他们:
cell.firstcheckmark.tag = 0;
然后
- (void)checkmarkPressed:(id)sender {
UIButton *button = (UIButton*)sender;
if(button.tag == 0)
{
...
}
...
}
我认为你也可以使用:
UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
它可以获取按钮所在的单元格