Reputation: 992
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]
}
Upvotes: 13
Views: 3466
Reputation: 2754
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:
Upvotes: 8
Reputation: 2600
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]
}
Upvotes: 2