Принудительное пополнение на iPhone с программно созданным UIPopoverPresentationController

Мне нужно создать новое представление popover, поскольку якорь не отображается в Interface Builder во время компиляции.

В соответствии с этим сообщением реализация метода делегата заставит Popover на iPhone. (по причинам, которые я не понимаю)

Он отлично работает, когда на segue, как показано в сообщении. Но я не могу заставить это работать не-segue. (Popover действительно появляется на iPad)

Пожалуйста, помогите!

Код указан ниже:

func showOptions() {
    let contentView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("PasteOption") as NewPasteOptionViewController
    contentView.modalPresentationStyle = UIModalPresentationStyle.Popover
    contentView.preferredContentSize = CGSizeMake(200.0, 200.0)
    presentViewController(contentView, animated: true, completion: nil)
    var _popoverPresentationController = contentView.popoverPresentationController!
    _popoverPresentationController.delegate = self
    _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any
    _popoverPresentationController.sourceView = view
    _popoverPresentationController.sourceRect = self.navigationItem.titleView!.frame
}
// this function below is never called.
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

Дополнительные примечания:

Представляющий контроллер представлений представлен в виде модальной формы в другом виде и инкапсулирован в контроллер навигации. Представленный контроллер представления представляет собой настраиваемый контроллер представления таблиц.

Ответы

Ответ 1

Кажется, что перемещение строки presentViewController(contentView, animated: true, completion: nil) до конца функции устранит проблему.

Ответ 2

let contentView  = 
PLMainNavigationManager.sharedInstance.storyboard.instantiateViewControllerWithIdentifier("PLSearchVCID") as! PLSearchVC
        contentView.modalPresentationStyle = UIModalPresentationStyle.Popover
        contentView.preferredContentSize = CGSizeMake(400.0, 500.0)
        var _popoverPresentationController = contentView.popoverPresentationController!
        _popoverPresentationController.delegate = self
        _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any
        _popoverPresentationController.sourceView = self.view
       _popoverPresentationController.sourceRect = CGRectMake(-30, -280, 320, 400)  
        PLMainNavigationManager.sharedInstance.navigationController?.presentViewController(contentView, animated: true, completion: nil)