如何将另一个Storyboard称为popover?

时间:2016-01-07 04:21:10

标签: ios xcode swift ios8 storyboard

假设有一个' ViewControllerOne '在故事板' A '。如果用户点击了该按钮,则 ViewControllerOne '将调用Storyboard' B '并将其显示为屏幕上的弹出框。似乎我找不到任何关于我的问题的参考资料。

我想从故事板中调用另一个故事板并将其显示为弹出窗口,是否可以执行此操作?谢谢。

修改

我已经尝试过@Sohil R. Memon提供的解决方案,但是我收到了一个错误:

reason: 'Storyboard (<UIStoryboard: 0x7fe69a841f00>) doesn't contain a view controller with identifier 'PaymentOnly''

我已将RestorationID添加到View Controller。

但是,如果我将代码更改为:

let storyBoard : UIStoryboard = UIStoryboard(name: "PaymentOnly", bundle:nil)
let navigationController: UINavigationController = storyBoard.instantiateInitialViewController() as! UINavigationController
let viewController = navigationController.viewControllers[0] as! PaymentOnlyViewController
self.navigationController?.pushViewController(viewController, animated: true)

它有效,但不会超出视图。以下是@Sohil R. Memon的代码:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "PaymentOption" {
        let storyBoard = UIStoryboard(name: "PaymentOnly", bundle: nil)
        let vc = self.storyboard!.instantiateViewControllerWithIdentifier("PaymentOnly") as! PaymentOnlyViewController
        self.presentViewController(vc, animated: false, completion: nil)
    }
}

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以在UIViewController任意位置显示/突出显示任何UIStoryBoard

期望这是您的第一个UIViewController,并且您想要从其他UIViewController拨打任何其他UIStoryBoard。因此,找到以下代码:

let storyBoard = UIStoryboard(name: "storyboard_name", bundle: nil)
let vc = self.storyboard!.instantiateViewControllerWithIdentifier("chatVC") as! ChatVC
self.presentViewController(vc, animated: false, completion: nil)

这样您就可以展示或推送任何UIViewController

Popover reference link