UITabBarController仅显示其UITabBar的一半(关闭屏幕)

时间:2011-06-18 21:40:25

标签: iphone objective-c uitabbarcontroller uitabbar

在我从UIViewController呈现UITabBarController后,我的UITabBar没有完全显示。请你告诉我我做错了什么?

我的代码是:

//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];
}

2 个答案:

答案 0 :(得分:1)

这不是一个好习惯:

[viewController1.view addSubview:viewController2.view];

MVC设计的重点丢失了。视图控制器应该从模型中获取数据并将其放入视图中。如果您有多个视图,只需安排视图的功能即可接受相应的数据。

因此,如果您需要标签栏控制器,则应执行以下操作:

// 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:你不应该继承UINavigationController和UITabBarController。

答案 1 :(得分:0)

实际上根据Apple的建议,UITabBarViewController应该是UIWindow层次结构中的根。我们很难尝试将TabBar VC或Navigation VC放到根目录。