在swift中的Popover ViewController中添加String Array

时间:2015-11-03 14:44:37

标签: swift

我正在开始iOS开发,我想知道如何插入

var typeBugList = ["string1", "string2", "string3"]

通过popover进入ViewController。目前我在下面有这个代码,它可以通过popover显示ViewController:

@IBAction func PopoverType(sender: UIButton)
 {


    let storyboard : UIStoryboard = UIStoryboard(
        name: "BugReporting",
        bundle: nil)
    let menuTypeViewController = storyboard.instantiateViewControllerWithIdentifier("MenuTypeViewController")

    menuTypeViewController.modalPresentationStyle = .Popover
    menuTypeViewController.preferredContentSize = CGSizeMake(300, 200)

    let popoverMenuViewController = menuTypeViewController.popoverPresentationController

    popoverMenuViewController?.permittedArrowDirections = .Left
    popoverMenuViewController?.delegate = self
    popoverMenuViewController?.sourceView = (sender as UIView)
    popoverMenuViewController?.sourceRect = sender.bounds

    presentViewController(menuTypeViewController, animated: true, completion: nil)
}

提前致谢!

1 个答案:

答案 0 :(得分:0)

在MenuTypeViewController文件中添加

var myArray : [String]

你的功能应该是

@IBAction func PopoverType(sender: UIButton)
 {


    let storyboard : UIStoryboard = UIStoryboard(
        name: "BugReporting",
        bundle: nil)
    let menuTypeViewController = storyboard.instantiateViewControllerWithIdentifier("MenuTypeViewController")

    menuTypeViewController.modalPresentationStyle = .Popover
    menuTypeViewController.preferredContentSize = CGSizeMake(300, 200)

    let popoverMenuViewController = menuTypeViewController.popoverPresentationController

    popoverMenuViewController?.permittedArrowDirections = .Left
    popoverMenuViewController?.delegate = self
    popoverMenuViewController?.sourceView = (sender as UIView)
    popoverMenuViewController?.sourceRect = sender.bounds

    menuTypeViewController.myArray = typeBugList

    presentViewController(menuTypeViewController, animated: true, completion: nil)
}