我有一个来自被调用的UITableViewController
填充。NSManagedObjects
NSFetchRequest
viewDidLoad
除了返回0myTableViewController
之外,一切都在 上按预期工作。accessoryButtonTappedForRowWithIndexPath
indexPath
这是我的实施方式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
如果你正在运行一堆 segue,你要小心。就我的目的而言,它有效。感谢 Tom Harrington 为我指明了正确的方向。