在Swift中调用另一个视图

时间:2014-06-06 12:12:16

标签: swift

我正试图在Swift中以编程方式调用视图,但我没有成功。

我在Objective-C找到了这个:

EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:@"EnterName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];

我怎样才能在Swift中做到这一点?

3 个答案:

答案 0 :(得分:6)

Swift中存在完全相似的方法:

let newEnterNameController = EnterNameController(nibName: "nibName", bundle: nil)
self.navigationController.pushViewController(newEnterNameController, animated: true)

答案 1 :(得分:3)

这对我有用:

let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil);
            let vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier("menu") as UIViewController;
            self.presentViewController(vc, animated: true, completion: nil);

答案 2 :(得分:0)

let viewController = mainStoryboard.instantiateViewController(withIdentifier: "identifier") as! ProductListVC
self.navigationController?.pushViewController(viewController, animated: true)