accessoryButtonTappedForRowWithIndexPath 在 Swift 2 中返回不需要的 indexPath

accessoryButtonTappedForRowWithIndexPath returning undesired indexPath in Swift 2

我有一个 UITableViewController 填充了 NSManagedObjects 来自 viewDidLoad 中调用的 NSFetchRequest

accessoryButtonTappedForRowWithIndexPath 外,myTableViewController 一切正常,returns indexPath 0.

以下是我的实施方式 accessoryButtonTappedForRowWithIndexPath:

override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("reorderSequences", sender: UIButton())
}

这是我的 performSegueWithIdentifier:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "reorderSequences" {
            // Get a hold of the item to send to the destinationVC
            let button = sender as! UIButton
            let hitPoint = button.convertPoint(CGPointZero, fromCoordinateSpace: self.tableView)
            if let indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(hitPoint) {
                // ** Regardless of which accessoryButton I press, the indexPath 
                // for index 0 is always the value **
                print("\nhitPoint's x: \(hitPoint.x)\n hitPoint's y: \(hitPoint.y)")
                let selectedThingSequence = self.thingSequences[indexPath.row] 
                print("prepareForSegue's indexPath is \(indexPath)")
            // set up the segue
                let destinationVC = segue.destinationViewController as! ReorderTableViewController
                destinationVC.thingSequenceToReorder = selectedThingSequence
                print(controller.description)
            }
        }
    }

我的理解是使用 UIButton 作为发件人让我弄清楚发件人住在哪个 indexPath performSegueWithIdentifier。显然,事实并非如此。我错过了什么?

更新

对于每个简单的问题,都有一个简单的答案:

prepareForSegue 我制作了 indexPath sender,像这样:

override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
            performSegueWithIdentifier("reorderThings", sender: indexPath)
}

prepareForSegue 中,我得到了这样传递的 indexPath:

let indexPath = sender as! NSIndexPath

如果你是 运行 一群 segues,你要小心。就我的目的而言,它有效。感谢 Tom Harrington 为我指明了正确的方向。

这一行:

performSegueWithIdentifier("reorderSequences", sender: UIButton())

您没有发送 "the" UIButton。您正在创建 UIButton 的全新实例。这不是你点击的那个。它不在屏幕上或视图层次结构中的任何地方。它对所有内容都有默认值。因此,当您开始执行 segue 时,传入的 UIButton 中没有任何有用的信息,并且您每次都会得到相同的结果。