2015-04-26 89 views
1

我創建了一個彈出窗口,但沒有任何顯示,我添加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 
} 

回答

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 
    } 

} 
+0

如何將文本或圖片添加到彈出窗口? – tanman

+0

我將如何啓動我自己的ViewController。我真的很新穎 – tanman

+0

我添加了這個'let storyboard:UIStoryboard = UIStoryboard( name:「Main」, bundle:nil) var menuViewController:interestViewController = storyboard.instantiateViewControllerWithIdentifier(「interestViewController」)as! interestViewController',但我得到一個SIBABRT錯誤。 – tanman