Swift - UITableView editActionsForRowAtIndexPath open UIPresentationController when click Edit
Asked Answered
S

2

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]
}
Spindrift answered 6/9, 2015 at 12:15 Comment(0)
M
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

Muskogean answered 13/9, 2015 at 2:17 Comment(3)
I said it's just an example of how to do it and enough for customization :) Please do the rest because I am sure you know how to make itMuskogean
I can't fix the arrow to be nearby Edit, and I don't know how to set height for vc which I use as storyboardSpindrift
Dude, it's completely different issue. If you expect people to help you more efficiently, give more details.Muskogean
C
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]
    }
Czarra answered 12/9, 2015 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.