Create Navigation Bar Programmatically in Swift

In your UIPopoverPresentationControllerDelegate:

func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
    let presentedViewController = controller.presentedViewController
    let navigationController = UINavigationController(rootViewController: presentedViewController)
    let dismissButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "dismissPopover:")
        
    presentedViewController.navigationItem.rightBarButtonItem = dismissButton
        
    return navigationController
}
    
func dismissPopover(sender: AnyObject) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

Leave a Reply

Your email address will not be published. Required fields are marked *