如果您的代码允许,我建议您将
UIButton标签设置为
indexPath.row,以便在触发其操作时可以拉出标签,从而在触发方法期间从按钮数据中移出。例如,
cellForRowAtIndexPath您可以设置标签:
button.tag = indexPath.rowbutton.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
然后在中
buttonClicked:,您可以获取标记,从而获取行:
func buttonClicked(sender:UIButton) { let buttonRow = sender.tag}否则,如果由于某种原因不利于您的代码,请将此Objective-C的Swift翻译答复为:
- (void)checkButtonTapped:(id)sender{ CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition]; if (indexPath != nil) { ... }}是:
func checkButtonTapped(sender:AnyObject) { let buttonPosition = sender.convert(CGPoint.zero, to: self.tableView) let indexPath = self.tableView.indexPathForRow(at: buttonPosition) if indexPath != nil { ... }}


