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

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

问题描述

我有一个UINavigationController,其中包含UITableViewController.该导航控制器将其他UITableViewController推到周围,最终这些表视图控制器将出现提示.

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

(导航栏隐藏了搜索栏)

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

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似乎没有顶部/底部布局指南,所以我无法创建约束(解决方案

我试图重现您的问题,并且似乎当不是所有的viewControllers都提示时,navigationBar还是无法正确调整大小.

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

中添加它

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

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

}

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

希望这对您也有用.

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)

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

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.

解决方案

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.

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

}

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.

Hope this works for you too.

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

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