view - 如何以编程方式使用另一个 View 中的按钮从 Storyboard 中打开 UIViewController?

标签 view swift ios8

我正在尝试从代码中打开 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/

相关文章:

view - Vim 在文件夹查看模式下更改配置

swift - 来自数组元素的 NSPredicate IN 查询

ios - url(forUbiquityContainerIdentifier) 返回 nil

iOS 8 在 UITableViewCell 边界之外绘制

ios - iOS 7 上的自动布局崩溃,在 iOS 8 上运行良好

objective-c - 不知道如何使用 NSTimer 更改 View

android - 为什么在尝试为按钮调用方法时程序崩溃?

mysql - 创建 VIEW 但更改所选列的数据类型

ios - 在 UINavigationBar 顶部添加 UIView 时如何重叠状态栏?

swift - 在带有属性字符串的 UITextView 中显示来自带有占位符的 url 的图像