在swift按钮上打开新屏幕

时间:2016-08-04 05:44:41

标签: ios swift

我是swift iOS的新手。在我的故事板中,我已经从viewController创建了一些动态字段。已经从对象库创建了一个按钮。

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

但我无法打开空屏幕。

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

}

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

5 个答案:

答案 0 :(得分:4)

1-From实用工具在故事板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);
}

答案 1 :(得分:1)

在Main.storyboard中创建Scan,如下所示 -

enter image description here 点击@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) } 按钮,执行以下代码

message: [{"latlng":[37*Math.random(),-82*Math.random()]},
                 {"latlng":[37*Math.random(),-82*Math.random()]},
                 {"latlng":[37*Math.random(),-82*Math.random()]},
                 {"latlng":[37*Math.random(),-82*Math.random()]}]
      });

有很多答案,只需进行搜索 -

答案 2 :(得分:1)

做简单的方法。将segue从firstViewController连接到secondViewController.Next单击segue goto show属性检查器(右侧的第3个选项)。在标识符中给出“您的文本”。 在下面的行中写下你的按钮动作。         performSegueWithIdentifier(“你的文字”,发件人:无)

答案 3 :(得分:1)

只需在代码中使用this 迅速2,3x,4x

如果存在笔尖,     让vc =

YourViewControllerName(nibName:"YourViewControllerName",bundle:nil)
    self.navigationController?.pushViewController(vc,animated:true)

如果没有笔尖

let vc = YourViewControllerName()
self.navigationController?.pushViewController(vc,animated:true)

答案 4 :(得分:0)

SWIFT 4

基于@AbedalkareemOmreyh的答案:

  1. 转到实用程序,打开身份检查器,然后在情节提要ID中输入ID“ MySecondSecreen”。
  2. 将以下代码添加到您的按钮:

    @IBAction func SaveTgw(sender: AnyObject) {
       let storyboard = UIStoryboard(name: "Main", bundle: nil);
       let vc = storyboard.instantiateViewController(withIdentifier: "MySecondSecreen")
                  self.present(vc, animated: true, completion: nil);
    }
    
相关问题