2016-04-03 64 views
0

我想在UIPopoverPresentationController(如iOS設置應用程序)中顯示viewController,當我們選擇語言時。它在設備屏幕的中心呈現一個viewController! enter image description hereiPad上的UIPopoverPresentationController

但是,我的結果不是那樣的!

enter image description here

這是我的代碼:

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) 
} 

和委託:

extension DetailViewController: UIPopoverPresentationControllerDelegate { 
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
     debugPrint(controller.description) 
     return .Popover 
    } 

    func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { 
     let navController = UINavigationController.init(rootViewController: controller.presentedViewController) 
     return navController 
    } 
} 
+0

顯示代碼如何目前公關是否存在 –

+0

@JoeBenton我加了我的代碼:)) –

回答

2

嘗試呈現樣式設置爲表:

detailVC.modalPresentationStyle = UIModalPresentation.FormSheet 
+0

非常感謝你! –