gpt4 book ai didi

ios - 为什么 presentationController 不是 :viewControllerForAdaptivePresentationStyle: being called?

转载 作者:可可西里 更新时间:2023-11-01 04:51:00 25 4
gpt4 key购买 nike

我正在尝试通过自适应弹出窗口以编程方式呈现 View (例如,在 iPad 上的弹出窗口中,在 iPhone 上全屏显示)。为了能够关闭 iPhone 上呈现的 View Controller ,我尝试将其包装在导航 Controller 中,如 https://stackoverflow.com/a/29956631/5061277 所示。或者这里的好例子: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 asked for presentation style");
return .FullScreen
}

func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {

// This line _IS_NOT_ reached in the debugger
NSLog("Delegate asked for view controller");
return UINavigationController(rootViewController: controller.presentedViewController)


}
}

在调用 adaptivePresentationStyleForPresentationController 委托(delegate)方法时,不会调用 presentationController viewControllerForAdaptivePresentationStyle 委托(delegate)方法。因此,无法关闭 iPhone 上显示的 Controller 。

我已经在 iOS 8.1 到 8.4 上尝试过 XCode 6.4 和 7.0b2,无论是在模拟器上还是在设备上,在任何情况下我的代表都不会要求 viewControllerForAdaptivePresentationStyle。为什么?是否有我应该查看的build设置,或者安装 XCode 7 是否可以改变某些东西?这个确切的代码在上面的链接中显示为有效。

最佳答案

配置完成后需要呈现。或者使用 segue 使其更容易。

关于ios - 为什么 presentationController 不是 :viewControllerForAdaptivePresentationStyle: being called?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31224089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com