我创建了一个弹出窗口,但没有显示任何内容,我添加了UIViewControllers作为弹出窗口。为什么不起作用? http://puu.sh/hreL9/75081b2a90.png
class interestViewController: UIViewController, UIPopoverPresentationControllerDelegate {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "popoverSegue" {
let interestViewController = segue.destinationViewController as! UIViewController
interestViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
interestViewController.popoverPresentationController!.delegate = self
}
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
答案 0 :(得分:1)
我相信在这种情况下你不需要一个segue。您可以使用下面列出的示例。按下按钮时,它会从按钮显示弹出窗口。
import UIKit
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
var myPopover : UIPopoverPresentationController?
@IBAction func buttonPressed(sender: UIButton) {
// you can init your own View Controller here
var popOverView = self.storyboard?.instantiateViewControllerWithIdentifier("interestViewController") as! interestViewController
popOverView.preferredContentSize = CGSize(width: 250, height: 200);
var destNav = UINavigationController(rootViewController: popOverView)
destNav.modalPresentationStyle = UIModalPresentationStyle.Popover
self.myPopover = destNav.popoverPresentationController
self.myPopover?.delegate = self
self.myPopover?.sourceView = self.view
var theFrame = sender.frame
self.myPopover?.sourceRect = theFrame
destNav.modalPresentationStyle = UIModalPresentationStyle.Popover
destNav.navigationBarHidden = true
self.presentViewController(destNav, animated: true, completion: nil)
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
}