2014-12-29 11 views
15

Ich muss eine neue Popover-Ansicht erstellen, da der Anker während der Kompilierung in Interface Builder nicht sichtbar ist.Force Popover auf dem iPhone mit programmgesteuert erstelltem UIPopoverPresentationController

Gemäß this post erzwingt die Implementierung der Delegate-Methode Popover auf dem iPhone. (aus Gründen, die ich nicht verstehe)

Es funktioniert gut, wenn auf einem Weg wie in der Post gezeigt. Aber ich kann das nicht auf eine nicht-sequenzielle Weise erreichen. (Popover erscheint auf dem iPad)

Bitte helfen!

Der Code ist unten aufgeführt:

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 
} 

Anmerkungen:

die präsentierende View-Controller als modales Formularblatt in einer anderen Ansicht dargestellt wird, und in einem Navigationsregler verkapselt. Der dargestellte View-Controller ist ein benutzerdefinierter Tabellenansicht-Controller.

Antwort

9

Es scheint, die Zeile presentViewController(contentView, animated: true, completion: nil) bis zum Ende der Funktion verschieben würde das Problem beheben.

+1

Sie haben Recht. Neugierig, dass die Dokumentation diese Aussage zuerst gemacht hat (das bestimmte Stück Code hat keinen Delegiertensatz) –

+0

Delegierteneinstellung sollte vor presentViewController gestellt werden, was denkst du? – gabbler

+0

Wie erwarten Sie, dass die Präsentation erfolgreich ist, wenn Sie den Präsentationscontroller nach der Präsentation festlegen? –

1
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) 
Verwandte Themen