13

Hi is there any way to open an UIPresentationController when swipe left is triggered and it's click 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]
}
4

2 回答 2

8

The same as @patchdiaz, I am not 100% sure what you would like to do. However this code block may be enough to be customized to achieve your goal:

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]
}

It will show a popover right at the 'Edit' button position like this:

enter image description here

于 2015-09-13T02:17:50.667 回答
2

Not sure what you are asking here. Something like this should work (this is in 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]
    }
于 2015-09-12T21:25:56.233 回答