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

发布于 2024-11-15 20:57:31 字数 669 浏览 2 评论 0原文

当我从 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];
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不在是我 2024-11-22 20:57:31

这不是一个好的做法:

[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。

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.

倾`听者〃 2024-11-22 20:57:31

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文