如何以编程方式在另一个视图中使用按钮从故事板中打开UIViewController?

时间:2014-07-02 08:49:36

标签: view swift ios8

我正在尝试从代码中打开故事板中的视图,我不知道这有多开放。目标c是

 UIViewController *controller = [[UIViewController alloc] 
 initWithNibName:@"myXib" bundle:[NSBundle mainBundle]]; 
 [self.storyboard instantiateViewControllerWithIdentifier:@"myView"]; 

但我不知道如何在Swift中做到这一点。

我有我的代码插座声明,我使用它:

 @IBOutlet var viewAboutUs : UIView = UIView()

 UIView.animateWithDuration(0.2, animations: {

                        self.viewAboutUs.frame = CGRectMake(0, UIScreen.mainScreen().bounds.size.height, UIScreen.mainScreen().bounds.size.width, 260.0)

但是使用此代码,我的应用程序崩溃了。如何从代码中打开这个视图?

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

let controller1 = UIViewController(nibName: "myXib", bundle: nil);

let storyboard = UIStoryboard(name: "myStoryboard", bundle: nil)
let controller2 = storyboard.instantiateViewControllerWithIdentifier("myView") as UIViewController