title: UIPopoverPresentationController on iPad
body: <p>I want to present a viewController in UIPopoverPresentationController like iOS Setting App do when we choose language. It presents a viewController at center of device screen!
  <a href="https://i.stack.imgur.com/UXdKI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UXdKI.png" alt="enter image description here"></a></p>
  
  <p>But, my result is not like that!</p>
  
  <p><a href="https://i.stack.imgur.com/tVfUx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tVfUx.png" alt="enter image description here"></a></p>
  
  <p>This is my code:</p>
  
  <pre><code>func rightButtonPressed(rightBarButton: UIBarButtonItem) {
      let detailVC = self.storyboard?.instantiateViewControllerWithIdentifier("ExampleViewController") as! ExampleViewController
      detailVC.modalPresentationStyle = .Popover
      let popOverVC = detailVC.popoverPresentationController
      popOverVC?.permittedArrowDirections = .Any
      popOverVC?.barButtonItem = rightBarButton
      popOverVC?.sourceView = self.view
      popOverVC?.delegate = self
  
      self.presentViewController(detailVC, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>And the delegate:</p>
  
  <pre><code>extension DetailViewController: UIPopoverPresentationControllerDelegate {
      func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -&gt; UIModalPresentationStyle {
          debugPrint(controller.description)
          return .Popover
      }
  
      func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -&gt; UIViewController? {
          let navController = UINavigationController.init(rootViewController: controller.presentedViewController)
          return navController 
      }
  }
  </code></pre>