开发者

UITabBarController's TabBar is slightly hidden

My UITabBarController's tabBar is slightly off the view, please can you tell me what is wrong with my code:

LoggedInViewController *lvc = [[[LoggedInViewController alloc]
                               initWithAccount:account] autorelease];
[self presentModalViewController:lvc animated:YES];

- (void)viewDidLoad
{
    self.tabController = [[UITabBarController alloc开发者_JAVA技巧] init];
    LoggedInFeedNavigationController *navController;
    navController = [[LoggedInFeedNavigationController alloc]
                     initWithAccount:self.account];
    [self.tabController setViewControllers:
        [NSArray arrayWithObject:navController]];
    [self.view addSubview:self.tabController.view];
    [super viewDidLoad];
}


You are adding the tabController view as a subview, but you have not specified where it should be located within its parent view, or how it should be resized when the parent view changes size. Try the following:

- (void)viewDidLoad
{
    [super viewDidLoad]; // see note

    self.tabController = [[UITabBarController alloc] init];
    LoggedInFeedNavigationController *navController;
    navController = [[LoggedInFeedNavigationController alloc]
                      initWithAccount:self.account];
    [self.tabController setViewControllers:
        [NSArray arrayWithObject:navController]];

    UIView *tabView = self.tabController.view;
    [self.view addSubview:tabView];

    tabView.frame = self.view.bounds;
    tabView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleHeight);
}

Note: you are not required to call [super viewDidLoad], but if you do decide to call it, you should call it at the beginning of your viewDidLoad method, and not at the end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜