0

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

4

3 回答 3

1

我不确定这是不是最好的方法,但这正是我在上一个应用程序中所做的,而且效果很好。

尝试使标签栏视图控制器成为应用程序的根/初始视图控制器。

根据 Apple 的开发者类参考:

部署选项卡栏界面时,您必须将此视图安装为窗口的根目录。与其他视图控制器不同,标签栏界面永远不应安装为另一个视图控制器的子级。

完成此操作后,在情节提要中设置从标签栏视图控制器到登录视图控制器的模态 segue,将其命名为“segueLogin”并在标签栏视图控制器类的 viewDidAppear 方法中手动调用它。

if(!userHasLogin){
    [self performSegueWithIdentifier:@"segueLogin" sender:self];
}
于 2014-02-13T18:02:39.507 回答
1

它真的很容易,

我将尝试分两步解决您的问题。

第 1 步——在情节提要中选择您的 TabViewController 并给它一个标识符(在 TabViewController 的客户类下方)

第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];    
}
于 2014-02-13T18:47:35.020 回答
0

您应该TabViewController使用UIStoryboard's创建您的- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier 在您的情况下创建 with[[TabViewController alloc] init]是错误的,您不会以编程方式创建所有选项卡。

于 2014-02-13T18:40:38.660 回答