2016-08-04 146 views
3

我是swift iOS的新手。在我的故事板中,我创建了一些来自viewController的动态字段。已经从对象库创建了一个按钮。在swift上点击按钮打开新屏幕

现在我需要点击这个按钮后打开一个新的空屏幕。 在新屏幕中,会有一些输入字段。我会通过编程或对象库创建这些。

但我无法打开空白屏幕。

@IBAction func SaveTgw(sender: AnyObject) { 
    print("test=====") 

} 

我需要在SaveTgw内包含屏幕开启代码。任何帮助或教程描述链接,将不胜感激....

+0

查看下面的答案 –

+1

yes - 我在检查。 – ripa

回答

4

1 - 从实用程序在故事板ID打开身份检查器中输入ID “MySecondSecreen”

enter image description here


2,在你的方法添加以下代码:

@IBAction func SaveTgw(sender: AnyObject) { 
     let storyboard = UIStoryboard(name: "Main", bundle: nil); 
     let vc = storyboard.instantiateViewControllerWithIdentifier("MySecondSecreen") as! UIViewController; // MySecondSecreen the storyboard ID 
     self.presentViewController(vc, animated: true, completion: nil); 
} 
+0

它工作。谢谢。 – ripa

1

创建Main.storyboard一个SecondViewController这样的 -

enter image description hereScan按一下按钮,就下面的代码

@IBAction func scanAction(sender: AnyObject) { 
    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) 

let secondViewController = storyBoard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController 
self.presentViewController(secondViewController, animated:true, completion:nil) 
} 

有有很多答案可供选择,只是做一个搜索 -

+0

好 - 谢谢你。我正在检查 – ripa

0

做简单的方法。将segView从firstViewController连接到secondViewController。然后单击segue goto show属性检查器(右侧第三个选项)。在标识符中给出“您的文本”。 在下面的行写入你的按钮动作。 performSegueWithIdentifier(“your text”,sender:nil)