Swift - UITableView editActionsForRowAtIndexPath 在点击编辑时打开 UIPresentationController

Swift - UITableView editActionsForRowAtIndexPath open UIPresentationController when click Edit

您好,有什么方法可以在触发向左滑动并单击时打开 UIPresentationController Edit

    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
        let delete = ....
        let edit = UITableViewRowAction(style: .Normal, title: "Edit") { action, index in
            //OPEN UIPresentationController HERE
        }
        return [delete, edit]
}

不确定你在这里问什么。像这样的东西应该可以工作(在 Swift 2 中):

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->
        [UITableViewRowAction]? {
            let delete = ...
            let edit = UITableViewRowAction(style: .Normal, title: "Edit") { [weak self] _ in
                let viewController = ...
                viewController.modalPresentationStyle = .Custom
                self?.presentViewController(viewController, animated: true, completion: nil)
            }
            return [delete, edit]
    }

和@patchdiaz一样,我不是100%确定你想做什么。但是,此代码块可能足以自定义以实现您的目标:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    let edit = UITableViewRowAction(style: .Normal, title: "Edit") { action, index in
        // OPEN UIPresentationController HERE
        let vc = UIViewController(nibName: nil, bundle: nil)
        vc.view.frame = CGRect(x: 0, y: 0, width: 100, height: 200)
        vc.view.backgroundColor = UIColor.orangeColor()
        vc.modalPresentationStyle = .Popover

        let popover = vc.popoverPresentationController!
        let cell = tableView.cellForRowAtIndexPath(indexPath)!

        var cellAbsolutePosition = cell.superview!.convertPoint(cell.frame.origin, toView: nil)
        cellAbsolutePosition.x = cell.frame.width - 60
        popover.sourceRect = CGRect(origin: cellAbsolutePosition, size: cell.frame.size)
        popover.sourceView = tableView

        self.presentViewController(vc, animated: true, completion: nil)
    }
    return [edit]
}

它将在 'Edit' 按钮位置右侧显示弹出窗口,如下所示: