Подтвердить что ты не робот

Swift - UITableView editActionsForRowAtIndexPath открывает UIPresentationController, когда нажимает 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]
}
4b9b3361

Ответ 1

Точно так же, как @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]
}

Он отобразит popover прямо в позиции "Изменить", как показано ниже:

введите описание изображения здесь

Ответ 2

Не уверен, что вы здесь задаете. Что-то вроде этого должно работать (это в 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]
    }