Question

I have an application that has an initial view controller that allows the user to log in. After the users logs in I'm trying to change the view to a custom tab bar controller that is of class type TabViewController. The problem is that when I switch to the tab bar controller, the screen is black and the bottom tab bar is gray and empty.

Here is some relevant code:

in ViewController.m (initial log in view)

- (IBAction)logInButtonClicked:(UIButton *)sender
{
    TabViewController *tabView = [[TabViewController alloc] initWithSession:session];
    [self presentViewController:tabView animated:YES completion:nil];
}

in TabViewController.m (class assigned to the tab bar controller)

-(id) initWithSession: (Session*) s
{
    self = [super init];

    if (self)
    {
        session = s;
    }

    return self;
}

Note that when I do the default initialization like so:

TabViewController *tabView = [[TabViewController alloc] init];

I get the same result.

How can I make my tab view controller look like it does in my storyboard on initialization?

Storyboard:

enter image description here

What the tab view controller looks like in the simulator:

enter image description here

Was it helpful?

Solution

I'm not sure this is the best way but it's exact what I did in my last app and it works fine.

Try making the tab bar view controller the root/initial view controller of your app.

According to Apple's developer class reference:

When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

After doing this, set up a modal segue in the storyboard from the tab bar view controller to the login view controller, name it "segueLogin" and call it manually in viewDidAppear method of your tab bar view controller class.

if(!userHasLogin){
    [self performSegueWithIdentifier:@"segueLogin" sender:self];
}

OTHER TIPS

its really easy,

i will try to solve your problem in two step.

step 1-- select your TabViewController in storyboard and give it a identifier(below the custome class of TabViewController)

step 2--

- (IBAction)logInButtonClicked:(UIButton *)sender
{
 UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:@"Your_Story_Board_Name" bundle:nil];
TabViewController *tabView = [storyBoard instantiateViewControllerWithIdentifier:@"TabViewController_Identifier_From_Storyboard"];
[self presentViewController:tabView animated:YES completion:nil];    
}

You should create your's TabViewController with UIStoryboard's - (id)instantiateViewControllerWithIdentifier:(NSString *)identifier In yours case creating with [[TabViewController alloc] init] is wrong, you doesn't create all tabs programmatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top