我正在尝试从代码中打开 Storyboard中的 View ,但我不知道如何打开它。在 objective-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)
但是使用这段代码,我的应用程序崩溃了。如何从代码中打开此 View ??
最佳答案
尝试这样的事情:
let controller1 = UIViewController(nibName: "myXib", bundle: nil);
let storyboard = UIStoryboard(name: "myStoryboard", bundle: nil)
let controller2 = storyboard.instantiateViewControllerWithIdentifier("myView") as UIViewController
关于view - 如何以编程方式使用另一个 View 中的按钮从 Storyboard 中打开 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24526741/