I want to place Table View exact down to navigation bar - ios

Please see the dashed-box area, this is extra space appearing between navigation bar & table view.
I've tried 3 things but same problem.
1. Cleared all constrains & "Add missing constrains"
2. I've used pin, & keep '0' distance to UI object above table view
3. I've used dragging method, & set vertical spacing for table view.

You nee to uncheck the property inside attribute inspector Adjust Scroll View Insets using storyboard see image below.
Edit:
Adjust Scroll View Insets: Defines a Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.
The default value of this property is true, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to false if your view controller implementation manages its own scroll view inset adjustments.

Select View Controller and Check Adjust scroll View insets.

I've done it, I was placing table view under navigation bar, now I've placed it exactly touching upper bounds of the view. And added missing constrains. enter image description here

Use this line in your tableview class's viewDidLoad method,
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
This sets the content from top.
It will be helpful for you.

-(void)viewDidLoad{
[super viewDidLoad:animated];
self.automaticallyAdjustsScrollViewInsets = NO;
}

By adding following line in viewDidLoad will solve this issue
self.navigationController?.navigationBar.translucent = false

Related

Table view top space to navigation bar increased after pressing back

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:
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.
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.
I'm not sure if this is related to your particular issue, but it's worth checking whether your UITableView is the first control on your screen:
Why is there extra padding at the top of my UITableView
Even in the latest version of Xcode, this is a bug. But it's easy enough to fix, if you know how to get around it.

iOS UIPageViewController child view under Bottom Bar

I had an UIPageViewController embedded in a NavigationController embedded an TabBarController.
I supposed every child view of the UIPageViewController fits the size within the UITabBarViewController.
The first child view looks fine:
Switch to the next (vertically), it's view suddenly resizes and the view length expands over the bottom bar:
Actually it's not under the bottom bar but clipped to that size (which means if you pull up the view you still cannot see the whole but the cut text).
I did unchecked every related view controller's Under Bottom Bar & Adjust Scroll View Inset but nothing works.
Any suggestion would be appreciated.
Try this in table view controller viewDidLoad() method.
self.extendedLayoutIncludesOpaqueBars = NO;
OR
you can set property in Interface Builder:
Uncheck Extend Edges: Under Bottom Bars, Under Opaque Bars.

Removing extra space at top of uicollectionview

I have xib in which button and uicollectionview appears as follows:
Now, when I run it , it appears as follows:
I want to remove white space above photos. I want to show photos just below from button. I have not marked header section in xib too. But, when I scroll up, the images move upto just below buttton too.This means frame is starting from just below button, but, I am getting extra white space.
So, can anybody help me to remove extra white space?
Add this code to your Controller class
- (void)viewDidLoad
{
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = NO;
}
Here is doc for automaticallyAdjustsScrollViewInsets
Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
I had the same problem. What work for me was to set automaticallyAdjustsScrollViewInsets = NO not only on the ViewController containing the CollectionView but on its parent ViewController too, because the child ViewController was in a ContainerView.
It can be done in the Interface builder too:
Auto adjust scroll view insets

UISearchBar on UITableView strange offset issue

I have a UITableView which has a UISearchBar subview. This is all on the view of a UIViewController along with a few other subviews (labels, text fields and such).
The search bar and content offset of the table are acting quite strangely, but it seems dependent on the order in which these views are added to the main view in the xib. I created a sample project with just my table/search and a label in order to test, and the result is the same. When the table is added after the label, everything works fine:
Setup:
Correct and Expected Result:
However, if I simply change the order in which my 2 subviews sit on the main view (aka table added before the label) then weird things start happening.
Apparently bad setup:
Weird offset of Search Bar:
I'm not changing anything else whatsoever, so why does Xcode seem to care which order these subviews are added to the main view?? If I scroll up on the "bad" table setup, the search bar disappears immediately at its top edge, but the table's content will continue to scroll up until it reaches the top of the frame that was set in the xib. Scroll back down and the search bar doesn't reappear until the strange lowered location. This is in Xcode 5.1.1, not the new beta. The result is the same with or without Autolayout turned on.
Any idea why this is happening? Is this a bug, or am I missing something? (I didn't post any code because all I'm doing is setting the number of sections, rows, and setting the text on the cell. Not messing with content insets, offset, anything. I load the view from the app delegate as the root of a nav controller)
This happens because a UIViewController's property called automaticallyAdjustsScrollViewInsets
With iOS 7, UIViewControllers have a property called
automaticallyAdjustsScrollViewInsets, and it defaults to YES. If you
have a scroll view that is either the root view of your view
controller (such as with a UITableViewController) or the subview at
index 0, then that property will adjust both the contentInset and the
scrollIndicatorInsets. This will allow your scroll view to start its
content and scroll indicators below the navigation bar (if your view
controller is in a navigation controller).
From Big Nerd Ranch
If you are using storyboards, you can change it by selecting the view controller and in the attributes inspector deselect Adjust scroll view insets.
Here is its description from apple documentation:
Default value is YES, which allows the view controller to adjust its
scroll view insets in response to the screen areas consumed by the
status bar, navigation bar, and toolbar or tab bar. Set to NO if you
want to manage scroll view inset adjustments yourself, such as when
there is more than one scroll view in the view hierarchy.
I have same problem before about position of tableview and searchbar. i tried the following and it works for me.
If you do not write code for that and if it is only problem of xib or storyboard then try all outlet's autosizing and origin setting to fix its position and see the difference. it may be work for you.
Update : automaticallyAdjustsScrollViewInsets has been deprecated in ios 11 and a new field contentInsetAdjustmentBehavior has been introduced.
if #available(iOS 11.0, *) {
tableview.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
UITableView header can contains only one UIView, so if you need UISearchBar plus UILabel, you need to wrap they into UIView and add this view as UITableView header.

Can you set the scroll view insets for container controllers?

I have a container controller that displays a bar of data right below the lop layout guide.
I want the child controller of the this container controller to be able to scroll behind this bar as well as any navigation bar and status bar. However it seems that when UIKit automatically adjusts the scroll view insets of a controller it only takes into account the length of the top layout guide.
Is there any way to be say that the scroll view insets should be the top layout guide + the height of my bar? I know people are going to suggest I set automaticallyAdjustsScrollViewInsets = NO but I have already tried this. The problem is that I cannot seem to replicate exactly when UIKit sets the content insets and so I get all sorts of weird edge cases that break the insets. The most prominent example being UITableViewController where, because I set the content insets manually, the refresh control is sometimes not in the correct position and when I end refreshing the insets of the scroll view get set to { 0, 0 } so content is hidden behind my bar and the navigation bar.
UPDATE: All the magic seems to be inside the methods _setNavigationControllerContentInsetAdjustment on UIViewController and _computeAndApplyScrollContentInsetDeltaForViewController on UINavigationController.
It appears that only the navigation controller attempts to adjust the scroll view insets and it calculates the insets based on the top and bottom layout guides. It passes these insets onto the view controller which then adds/subtracts the insets from the scroll view and takes into consideration what navigation content insets have been set previously. This ensures that if anyone else modified the content insets between now and when the navigation controller last modified the insets they will not override the intermediary changes.
My solution was to set automaticallyAdjustsScrollViewInsets = NO and handle the setting of the content insets myself.
I created a category on UIViewController that tracked any existing insets that were set so whenever I adjusted the insets to have the scroll view appear below my custom UIView I would not be losing any information, such as the content inset for the UITableViewController with a active refresh control inside it.
After that the last challenge was figuring out where to set the custom insets and after much experimenting I found that - (void)viewDidLayoutSubviews was the best place to do it.
FDScrollingTabBarController is the container controller that I implemented this solution in.

Resources