我试图通过自适应弹出窗口以编程方式呈现视图(例如,在iPad上的popover,iPhone上的全屏)。为了能够解除iPhone上呈现的视图控制器,我尝试将其包装在导航控制器中,如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委托方法时,不会调用presentationController viewControllerForAdaptivePresentationStyle委托方法。因此,无法解除iPhone上呈现的控制器。
我已经在iOS 8.1到8.4上尝试过XCode 6.4和7.0b2,无论是在模拟器中还是在设备上,在任何情况下我的委托都不会要求viewControllerForAdaptivePresentationStyle。为什么?是否有我应该看的构建设置,或者安装XCode 7是否会改变某些东西?这个确切的代码显示为在上面的链接中工作。
答案 0 :(得分:1)
配置后需要显示它。或者使用segue使其更容易。
答案 1 :(得分:0)
您需要添加此方法:
affectedUserIds
答案 2 :(得分:0)
诀窍是您必须设置 演示控制者的代表,然后调用 present(_:animated:completion:); 否则,自适应演示文稿委托方法将不会被调用:
Caused by: java.lang.ClassNotFoundException: com.example.foglight.config.db.DatabaseModelNamingStrategy
at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.jooq.codegen.GenerationTool.loadClass (GenerationTool.java:819)
at org.jooq.codegen.GenerationTool.run (GenerationTool.java:352)
at org.jooq.codegen.GenerationTool.generate (GenerationTool.java:220)
at org.jooq.codegen.maven.Plugin.execute (Plugin.java:197)