无法显示第一个控制器iOS Swift

时间:2016-04-01 07:44:27

标签: ios

下面是我的代码,我无法加载第一个视图控制器,建议我不使用嵌入式导航控制器。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

    let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
    let firstViewController = storyBoard.instantiateViewControllerWithIdentifier("LoginViewController")
    self.window?.rootViewController = firstViewController
    return true
}

4 个答案:

答案 0 :(得分:1)

你需要通过代码吗?由于您的视图控制器位于故事板中,您只需单击视图控制器并勾选该框即可使其成为初始视图控制器,从而实现与代码相同的功能:

enter image description here

答案 1 :(得分:1)

1)确保填写故事板的正确名称。 2)检查视图控制器的标识符名称。

然后,

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let initialViewController = storyboard.instantiateViewControllerWithIdentifier("LoginViewController") as UIViewController

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

    return true
}

答案 2 :(得分:0)

let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())

在这里更改您的故事板名称。

答案 3 :(得分:0)

如果你使用故事板,你必须在故事板中设置初始视图控制器," self.window?.rootViewController"不会工作 enter image description here