ios – UITabBarController – Child(Tab)ViewControllers的不正确和不一致的边界

前端之家收集整理的这篇文章主要介绍了ios – UITabBarController – Child(Tab)ViewControllers的不正确和不一致的边界前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带有两个选项卡的UITabBarController.每个选项卡都是UITableViewController.

当UITabBarController出现时,两个选项卡视图都有不正确的边界.第一个选项卡正确位于导航栏下方,但延伸到底部的选项卡栏下方.第二个选项卡是另一种方式,从导航栏下方开始,但在底部的选项卡栏之前正确停止.

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

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

然后在TabBarController的init中,创建并添加子(tab)视图,如下所示:

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

第一个选项卡的行为已得到改进并且位置正确,但第二个选项卡保持不变.情况如下:

有什么建议?
干杯.

解决方法

问题是由我呈现UITabBarController的方式引起的
ActiveListTabBarViewController* listTabBarController = [[ActiveListTabBarViewController alloc] initWithListController:_listController];
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:listTabBarController];
[self presentViewController:nc animated:YES completion:^(){}];

回到Apple的文档,我不确定这是否是呈现UITabBarController的有效方式.也就是说,将其呈现为另一个视图控制器的子节点.

不是.以下是为我确认的一些片段;从这一点,以及由此产生的变化,我认为在我上面提供一个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作为导航控制器的根视图呈现的原因是我想要导航栏…

这就是我现在在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
> automaticAdjustsScrollViewInsets
> extendedLayoutIncludesOpaqueBars

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

原文链接:https://www.f2er.com/iOS/331947.html

猜你在找的iOS相关文章