No didSelectRowAtIndexPath() in tableView when edi

2020-04-18 07:14发布

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条回答
叛逆
2楼-- · 2020-04-18 07:29

AFAICS, you problem is that, on your table view, allowsSelectionDuringEditing is set to NO (or false, if you're using Swift).

查看更多
登录 后发表回答