gpt4 book ai didi

ios - UITabBarController - 子(选项卡)ViewControllers 的不正确和不一致的边界

转载 作者:可可西里 更新时间:2023-11-01 03:32:22 25 4
gpt4 key购买 nike

我有一个带有两个选项卡的 UITabBarController。每个选项卡都是一个 UITableViewController

UITabBarController 出现时,两个选项卡 View 各自具有不正确的边界。第一个选项卡正确地位于导航栏下方,但延伸到底部的选项卡栏下方。第二个选项卡正好相反,从导航栏下方开始,但正确地停在底部的选项卡栏之前。

enter image description here

我正在创建和呈现 TabBarController,如下所示:

ActiveListTabBarViewController* listTabBarController = [[ActiveListTabBarViewController alloc] initWithListController:_listController];
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:listTabBarController];
[self presentViewController:nc animated:YES completion:^(){}];

然后在 TabBarController 的 init 中,创建并添加子(选项卡) View ,如下所示:

_todoListViewController = [[BasicTableViewController alloc] initWithList:[_controller itemsToDo]];
_todoListViewController.delegate = self;
_todoListViewController.title = @"To Do";
_completedListViewController = [[BasicTableViewController alloc] initWithList:[_controller itemsDone]];
_completedListViewController.delegate = self;
_completedListViewController.title = @"Completed";

[self setViewControllers:@[_todoListViewController, _completedListViewController]];

我做错了什么?

谢谢,加文

更新:按照建议将以下方法添加到BasicTableViewController:

- (UIRectEdge)edgesForExtendedLayout
{
return UIRectEdgeNone;
}

第一个选项卡的行为有所改进并且位置正确,但第二个选项卡保持不变。现在情况如下:

enter image description here

有什么建议吗?干杯。

最佳答案

问题是由我呈现 UITabBarController

的方式引起的
ActiveListTabBarViewController* listTabBarController = [[ActiveListTabBarViewController alloc] initWithListController:_listController];
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:listTabBarController];
[self presentViewController:nc animated:YES completion:^(){}];

回到 Apple 的文档,我不确定这是否是呈现 UITabBarController 的有效方式。也就是说,将其呈现为另一个 View Controller 的子级。

不是。以下是一些片段,为我证实了这一点;由此以及由此产生的变化,我假设像上面那样呈现 TabBarController 是不正确的。

来自: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html

Before creating a tab bar interface, you need to decide how you intend to use a tab bar interface. Because it imposes an overarching organization on your data,you should use one only in these specific ways:

  • Install it directly as a window’s root view controller.
  • Install it as one of the two view controllers in a split view interface. (iPad only)
  • Present it modally from another view controller.
  • Display it from a popover. (iPad only)

来自: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

进一步说明:

A tab bar controller is a container view controller that you use to divide your app into two or more distinct modes of operation.

A navigation controller presents data that is organized hierarchically and is an instance of the UINavigationController class. The methods of this class provide support for managing a stack-based collection of content view controllers.

我将 UITabBarController 呈现为导航 Controller 的 Root View 的原因是我想要导航栏...

这就是我现在在 TabBarController 的 init 中实现它的方式:

- (id)initWithListController:(BasicListController *)controller
{
self = [super init];
if (self) {
_controller = controller;

_todoListViewController = [[BasicTableViewController alloc] initWithList:[_controller itemsToDo]];
_todoListViewController.delegate = self;
_todoListViewController.title = @"To Do";

_completedListViewController = [[BasicTableViewController alloc] initWithList:[_controller itemsDone]];
_completedListViewController.delegate = self;
_completedListViewController.title = @"Completed";

UINavigationController* ncTodo = [[UINavigationController alloc] initWithRootViewController:_todoListViewController];
UINavigationController* ncCompleted = [[UINavigationController alloc] initWithRootViewController:_completedListViewController];

[self setViewControllers:@[ncTodo, ncCompleted]];

UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneTap:)];
_todoListViewController.navigationItem.leftBarButtonItem = doneButton;
_completedListViewController.navigationItem.leftBarButtonItem = doneButton;
}
return self;
}

请注意,我无需对以下内容执行任何操作:

  • edgesForExtendedLayout
  • 自动调整 ScrollViewInsets
  • extendedLayoutIncludesOpaqueBars

iOS 7 默认尊重导航栏和标签栏(与上面的原始屏幕截图不同,当 UITabBarController 显示不正确时)。

关于ios - UITabBarController - 子(选项卡)ViewControllers 的不正确和不一致的边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21031884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com