以编程方式设置提示时,UINavigationBar 与 UITableView 重叠 [英] UINavigationBar overlaps UITableView when programmatically setting prompt

查看:17
本文介绍了以编程方式设置提示时,UINavigationBar 与 UITableView 重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UINavigationController,其中包含一个 UITableViewController.这个导航控制器会推动其他 UITableViewControllers,最终这些表格视图控制器会有提示.

I have a UINavigationController which contains a UITableViewController. This navigation controller pushes other UITableViewControllers around and eventually these table view controllers will have a prompt.

问题是当我以编程方式设置此提示时,它会与它下面的表格视图的内容重叠.

The problem is when I set this prompt programmatically it overlaps the content of the table view underneath it.

(搜索栏被导航栏隐藏)

(A search bar is being hidden by the navigation bar)

我在 SO 中环顾四周,发现 这个答案.我在受影响的视图控制器中以两种不同的方式尝试了该建议,但没有任何改变:

I was looking around in SO and found this answer. I tried the suggestion there in two different ways in the affected view controller but nothing changed:

override func viewDidLoad() {
    super.viewDidLoad()
    self.edgesForExtendedLayout = .None;
    self.extendedLayoutIncludesOpaqueBars = false;
    self.navigationItem.title = NSLocalizedString("Add Anime or Manga", comment: "")
    self.navigationItem.prompt = NSLocalizedString("Search media belonging to this series.",  comment: "")
}

-

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.title = NSLocalizedString("Add Anime or Manga", comment: "")
    self.navigationItem.prompt = NSLocalizedString("Search media belonging to this series.",  comment: "")
    self.edgesForExtendedLayout = .None;
    self.extendedLayoutIncludesOpaqueBars = false;
}

同一答案中的评论链接到 此 Apple 指南 关于防止视图相互重叠.问题是 UITableViewController 似乎没有顶部/底部布局指南,因此我无法创建约束(another SO answer 说在表格视图控制器中使用上述布局是无关紧要的).

A comment in that same answer linked to this Apple guide on preventing views from overlapping each other. The problem is UITableViewController doesn't appear to have top/bottom layout guides so I can't create a constraint (another SO answer says having said layouts in table view controllers is irrelevant).

因此,我已经用尽了所有选择.

As such I have exhausted all my options.

推荐答案

我已尝试重现您的问题,但似乎并非所有 viewControllers 都有提示 navigationBar 以某种方式无法正确调整大小.

I have tried to reproduce your problem and it seems that when not all the viewControllers have a prompt the navigationBar is somehow not resizing properly.

您似乎需要以某种方式触发 UINavigationController 的布局.我可以使它正常工作的唯一方法是在 viewWillAppear:

It seems you need to somehow trigger the layouting for the UINavigationController. The only way I could make it work properly was by adding this in viewWillAppear:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES];
    [self.navigationController setNavigationBarHidden:NO];

}

也许这个提示是为了在整个应用程序中一致地使用(意味着对所有视图控制器都有一个或没有一个),这就是为什么 UINavigationController 在更改时不会布局它的子视图.

Maybe this prompt is meant to be used consistently across the entire application (meaning having one for all viewControllers or none of them), that's why the UINavigationController does not layout it's subviews when it changes.

希望这对你也有用.

这篇关于以编程方式设置提示时,UINavigationBar 与 UITableView 重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆