UITabBarController only showing half of its UITabBar (off screen)

坚强是说给别人听的谎言 提交于 2019-12-02 10:25:16

问题


My UITabBar is not completely showing after I present a UITabBarController from a UIViewController. Please can you tell me what I am doing wrong?

My code is:

//some method

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

- (void)viewDidLoad

{
    self.tabController = [[UITabBarController alloc] init];
    LoggedInFeedNavigationController *navController = [[LoggedInFeedNavigationController alloc] initWithAccount:self.account];
    [self.tabController setViewControllers:[NSArray arrayWithObject:navController]];
    [self.view addSubview:self.tabController.view];
    [super viewDidLoad];
}

回答1:


It's not a good practice to do:

[viewController1.view addSubview:viewController2.view];

The point of the MVC design is lost. The view controller should get your data (from the model) and put it in the view. If you have more than one view just arrange the functionality of the views to accept the corresponding data.

So if you need a tab bar controller you should do the following:

// assuming you are in the same initial controller
UITabBarController* pTabBarControllerL = [[UITabBarController alloc] init];
MyFirstController* pFirstControllerL = [[MyFirstController alloc] init];
[pTabBarControllerL setViewControllers:[NSArray arrayWithObject:pFirstControllerL]];
// perhaps set more tab bar controller properties - button images and so on
[self presentModalViewController:pTabBarControllerL animated:YES];
// release the memory you do not need

-(void)viewDidLoad {
    // do your work in pFirstControllerL
}

PS: You should not subclass UINavigationController and UITabBarController.




回答2:


Actually according to the Apple's recommendations UITabBarViewController should be the root in the UIWindow hierarchy. We had hard times trying to put TabBar VCs or Navigation VCs not to the root.



来源:https://stackoverflow.com/questions/6399054/uitabbarcontroller-only-showing-half-of-its-uitabbar-off-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!