小编Chr*_*and的帖子

为什么不是presentationController:viewControllerForAdaptivePresentationStyle:被调用?

我正在尝试通过自适应弹出窗口以编程方式呈现视图(例如,在iPad上的popover,iPhone上的全屏).为了能够解除iPhone上呈现的视图控制器,我尝试将其包装在导航控制器中,如/sf/answers/2096964201/或这里的好例子:https:// github.com/shinobicontrols/iOS8-day-by-day/tree/master/21-alerts-and-popovers/AppAlert,看起来像:

import UIKit

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {

  @IBAction func handlePopoverPressed(sender: UIView) {
    let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("codePopover") as! UIViewController
    popoverVC.modalPresentationStyle = .Popover
    // Present it before configuring it
    presentViewController(popoverVC, animated: true, completion: nil)
    // Now the popoverPresentationController has been created
    if let popoverController = popoverVC.popoverPresentationController {
      popoverController.sourceView = sender
      popoverController.sourceRect = sender.bounds
      popoverController.permittedArrowDirections = .Any
      popoverController.delegate = self
    }
  }

  func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    // This line _IS_ reached in the debugger
    NSLog("Delagate …
Run Code Online (Sandbox Code Playgroud)

iphone ios

5
推荐指数
1
解决办法
912
查看次数

标签 统计

ios ×1

iphone ×1