Creating a programmatic tab bar with storyboard view controllers?

前端 未结 2 453
忘掉有多难
忘掉有多难 2021-02-03 13:23

I have a tab bar that is created programmatically and I\'m having difficulties initializing a storyboard associated with a view.

I\'m able to load the view successfully

相关标签:
2条回答
  • 2021-02-03 13:38

    Swift 4

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    settingsViewController = storyboard.instantiateInitialViewController()
    settingsViewController = storyboard.instantiateViewController(withIdentifier: "SettingsViewController")
    
    0 讨论(0)
  • 2021-02-03 13:41

    If you want to initialize the view controller as in the storyboard you have to use the storyboard methods instead of allocating the view controller directly:

    // load the storyboard by name
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    
    // either one of the two, depending on if your view controller is the initial one
    settingsViewController = [storyboard instantiateInitialViewController];
    settingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];
    
    0 讨论(0)
提交回复
热议问题