Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view top space to navigation bar increased after pressing back

Tags:

xcode

ios

swift

When I click one of the cells in the table view, it opens a new view with the following code:

   let fullResView : FullResponseViewController = self.storyboard?.instantiateViewControllerWithIdentifier("FullResponseView") as! FullResponseViewController
   fullResView.receivedPost = post
   self.navigationController?.pushViewController(fullResView, animated: false)

When I press back, it increases the distance between the table view and the Top Layout Guide. Representation:

table view navigation controller error.

Hierarchy:

  • I have a tab bar controller, that is embedded in a navigation controller.
  • The table view is drag & dropped after creating an normal view. So the table view is inside a View.
  • Table view does contain an header view. When setting a background color for this, it moves together with it, so it should not be anything with those constraints.

constraints for the table view are:

  • equal with to superview
  • Align Center X to superview
  • top space to Top Layout Guide
  • bottom space to Bottom Layout Guide

I've tried the following:

set this in viewWillAppear:

self.responsesTableView.contentOffset =  CGPointMake(0, 0)
self.automaticallyAdjustsScrollViewInsets = false

This did work when I pressed back, then switch to another view in the tab bar, and then switch back again. Without contentOffset it will stay like this forever.

like image 520
CularBytes Avatar asked Dec 15 '22 11:12

CularBytes


1 Answers

As i seen the OP images that seems like Navigation translucent property Issue. Because after push a viewcontroller there is same 44px white space. so it means if your Navigation translucent property is true then your UITableview start from 0th Y position. And if your Navigation translucent property is false then UITableview start from 44px Y position.

So i guess in between push and back some where UINavigation's translucent become a true and false. make following one line add in your appdelegate class in DidFinish method:

UINavigationBar.appearance().translucent = false

This is appearance of UINavigationBar for make this false globley in your project. Hope that will be fix your issue.

like image 54
Nitin Gohel Avatar answered Mar 15 '23 23:03

Nitin Gohel