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 comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.