Creating a programmatic tab bar with storyboard view controllers?

前端 未结 2 521
忘掉有多难
忘掉有多难 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: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"];
    

提交回复
热议问题