呈现视图控制器功能不被称为iOS Swift

时间:2015-04-30 22:21:30

标签: ios swift

对于此问题,运行此代码的视图控制器位于Login.storyboard IB文件中。我试图呈现的视图控制器位于Main.storyboard IB文件中。下面的代码是我用来从一个视图控制器转换到另一个视图控制器的代码。

func presentNextView() {
    let mainSb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let screenAfterLogin: UIViewController = mainSb.instantiateViewControllerWithIdentifier("MainContainerView") as! UIViewController
    self.presentViewController(screenAfterLogin, animated: true, completion: nil)
}

运行应用程序,我在presentNextView函数中执行的3行上设置了3个断点。调用第一行,调用第二行,但不调用第三行,并且不显示下一个屏幕。目前xCode有问题吗?

在github上查看项目:https://github.com/joshuarcher/RecallBeta

问题在于文件“HardLoginViewController.swift”

2 个答案:

答案 0 :(得分:0)

func presentNextView() {

    let mainSb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let screenAfterLogin: SecondVC = mainSb.instantiateViewControllerWithIdentifier("SecondVC") as SecondVC
    let navigationController = UINavigationController(rootViewController: screenAfterLogin)
    presentViewController(navigationController, animated: true, completion: nil)
}

答案 1 :(得分:0)

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        presentNextView()
    }

    func presentNextView() {
        let mainSb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        let screenAfterLogin: SecondVC = mainSb.instantiateViewControllerWithIdentifier("SecondVC") as SecondVC
        let navigationController = UINavigationController(rootViewController: screenAfterLogin)
        presentViewController(navigationController, animated: true, completion: nil)
    }
}


import UIKit

class SecondVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title="Second Screen"
    }
}