Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar overlaps UITableView when programmatically setting prompt

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.

enter image description here

(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.

like image 978
Andy Ibanez Avatar asked Dec 24 '22 21:12

Andy Ibanez


1 Answers

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.

like image 139
Catalina T. Avatar answered Jan 19 '23 00:01

Catalina T.