繁体   English   中英

编辑时tableView中没有didSelectRowAtIndexPath()

[英]No didSelectRowAtIndexPath() in tableView when editing

我想调用didSelectRowAtIndexPath() ,但是当我处于编辑模式时,不会触发该事件。 这是我的代码:

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
}

仅当self.editing == false时才调用didSelectRowAtIndexPath()

我究竟做错了什么?

AFAICS,您的问题是,在表视图上, allowsSelectionDuringEditing设置为NO (如果使用的是Swift,则为false )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM