问题
I want to call didSelectRowAtIndexPath()
, but the event won't be fired, when I'm in edit-mode. This is my code:
override func viewDidLoad() {
tableView.delegate = self
tableView.dataSource = self
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.tableView.deselectRowAtIndexPath(indexPath, animated:true)
let data = fetchedResultsController.objectAtIndexPath(indexPath) as! NSManagedObject
...
}
@IBAction func updateButtonClicked(sender: AnyObject) {
toggleEditing()
}
func toggleEditing() {
if self.editing {
super.setEditing(false, animated: true)
self.title = "Sicherung"
} else {
super.setEditing(true, animated: true)
let cancelBarButton = UIBarButtonItem(title: "Fertig", style: .Plain, target: self, action: "stopEdit:")
navigationItem.rightBarButtonItem = cancelBarButton
navigationItem.hidesBackButton = true
self.title = "Sicherung bearbeiten"
}
}
func stopEdit(sender: AnyObject) {
super.setEditing(false, animated: true)
let cancelBarButton = UIBarButtonItem(title: "Bearbeiten", style: .Plain, target: self, action: "toggleEditing")
navigationItem.rightBarButtonItem = cancelBarButton
navigationItem.hidesBackButton = false
}
didSelectRowAtIndexPath()
is only called when self.editing == false
.
What am I doing wrong?
回答1:
AFAICS, you problem is that, on your table view, allowsSelectionDuringEditing
is set to NO
(or false
, if you're using Swift).
来源:https://stackoverflow.com/questions/33874666/no-didselectrowatindexpath-in-tableview-when-editing