【问题标题】:Swift: How to use button to secondViewController by swift codeSwift:如何通过快速代码使用按钮到 secondViewController
【发布时间】:2016-03-13 18:01:02
【问题描述】:

我有两个 UIViewController,分别是 FirstViewControllet 和 SecondViewController。我正在使用 firstViewController 中的“显示”拍卖来连接两个 UIViewController。

我有一个问题,我不知道如何通过 swift 代码访问 secondViewController,可以帮我解决这个问题吗?谢谢

@IBOutlet weak var txtUserInput: UITextField!

@IBAction func btnSecondView(sender: AnyObject) {
    if (txtUserInput != 0) {
         print(User Input > 0)
         //go to SecondViewController
    } else {
         print(User Input < 0)
         //display alert message
    }
}

在情节提要上,我应该制作 Picture2 和 Picture3 吗?

图2:

  1. 建立连接。

图3:

  1. 选择Manual Segue的节目

我收到错误图片 4。 怎么解决呢,谢谢

图4:

【问题讨论】:

    标签: xcode swift2


    【解决方案1】:
    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    
    let SecondViewController = storyBoard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController
    self.presentViewController(SecondViewController, animated:true, completion:nil)
    

    确保将“SecondViewController”添加到情节提要中视图控制器的标识符选项卡中。

    【讨论】:

    • 如果您使用 Storyboard,那么可以。
    • 复制到第一个或第二个 ViewContoller 的 Swift 文件?
    • 复制到您拥有 // go to SecondViewController 的位置,并确保在您的 Storyboard 中,您在 Identifier 选项卡中输入 SecondViewController
    • 如果我的 SecondViewController 名称是 MainMenuPageViewController。代码将是 ' let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) let MainMenuPageViewController = storyBoard.instantiateViewControllerWithIdentifier("MainMenuPageViewController") as! MainMenuPageViewController self.presentViewController(MainMenuPageViewController, animated:true, completion:nil) '
    • 您好,可以帮帮我吗?
    猜你喜欢
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多