No didSelectRowAtIndexPath() in tableView when editing

为君一笑 提交于 2019-12-02 09:58:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!