why header of a section of a uitableview is abnormally tall when the uitableview is embedded to a uiviewcontroller? - ios

I would like to make a page like this (i.e. a fix segmented controller on the top, with a uitableview appending beneath it):
So, this is the way I did it: I have added a segmented controller in a uiviewcontroller, then I append a uitableview under it. Here is the diagram in the storyboard:
However, when it runs in the simulator, the header of the uitableview is abnormally tall.
I have no idea why it is like this. Am I going to a wrong direction? Thanks for any helps.
UPDATE:
This is the default setting of the uitableview. I didn't change any thing.

Select your view controller in storyboard. In the Attributes inspector, uncheck "Adjust Scroll View Insets" and uncheck "Under Top Bars".

You have placed Segment control in Tableview's header. But you had set some height to tableview section header via either xib or programmatically. That's why it leads to show this space.

Related

Why are my views inside the storyboard tableViewHeader visually misplaced?

When adding a tableview header in storyboard, by dragging a view onto the header area, subviews inside this header view seem to be visually misplaced. Is there a logical reason for this?
Reproducing the problem (Xcode 8):
Open storyboard
Drag a UITableViewController onto the canvas
Drag a UIView onto the tableview header area
Add any view as a subview on the header view:
This issue is only visible in storyboard though. At runtime, the views are aligned as expected.
Easy fix: Dont drag in there, drag it on the above like this, since you treat it as a view property to the view controller, not to it's view, when you drag into the view, it will treat your header view as a subview to the content view, that's not what you need
This issue is also applies to xib. When you drag views which the Simulated Metrics size is freedform onto tableView, system will treat the first subview as tableHeaderView, the second subview as tableFooterView automatically.

Space in the content of UITableView

Today I faced a weir bug in UITableView.
I have a UIViewController containing a UITableView. I also have a root viewcontroller, which will add the aforementioned UIViewController as a child.
Now when loaded, it shows a space between cells and the top border.
How can I fix that?
Try to deselect Adjust Scroll view insets option of the ComicsVC view controller.
First select ComicsVC item in the left window of your storyboard, then in the attributes inspector you will easily find this checkbox.
You have to set top position of UITableView to 0. Also you have to add constraints between UITableView and parent UIView.
This bug appears when you use translucent navigation bar.
That space shows up for grouped UITableViews, and is usually occupied by a section header. If you don't implement a section header, then the area will be blank.
If you don't have more than one section, go to the UITableView in the storyboard, show the properties, and change the style to Plain.
Hope this helps!

Hide Nav Bar and move Table View Section Headers

I am currently using the https://github.com/telly/TLYShyNavBar class to hide my nav bar when scrolling, it works great and is extremely simple to use. But I am using it on a table view controller so when I scroll up my section headers don't move and it looks like this.
How can I move up the section headers to the top of the screen. Or use a different way to move the nav bar when scrolling.
Thanks for the help in advance.
You could use the first TableViewCell as a custom navigation bar by adding buttons to the contentview contained in the TableViewCell. It would scroll up like any other TableViewCell. TableViewCells are mostly just a wrapper for a UIView. You can modify that UIView like any other UIView. Every TableViewCell has a property called contentview which is the main UIView in the Cell.
As an example, you could add a button to the first cell that sends the following message
[self.navigationController popViewControllerAnimated:YES];
You could call that button "Back"
https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UITableViewCell_Class/index.html#//apple_ref/occ/instp/UITableViewCell/contentView
I found a solution for this!
The problem is that, the section header stays at the top value of the contentInset. Even though the navigation bar is out of view and the tableView is visible below, the contentInset will remain same.
You would have to modify the library to increase or decrease the top value of the contentInset, according to the scrolling offset. Try this out and you may post it as a pull request in github.
Hope this helps! :)

Why content insets of a UITableView inside a UIPageViewController get messy right after an interaction?

I've created a Page-Based Application and hacked it a bit for some experiments; my simple aim is to have a UIPageViewController whose pages will contain a UIViewController holding a UITableView (after further inspection, the outcome of my experiment is the same if I use a UITableViewController instead).
To do this I've simply edited the project template, and added the UIPageViewController as an embedded view of the RootViewController using Storyboard's ContainerView object, as you can see in this screenshot:
Every controller is configured via storyboard to automatically adjust scroll view's content inset, and if I start the project with this configuration everything looks fine, and the DataViewController's tableview has its content insets properly adjusted right under the navigation bar as expected; however, as the user makes an interaction with the tableview, the content insets break and the tableview underlaps the navigation bar:
I have been able to fix this by manually setting the content insets in DataViewController's viewDidLayoutSubview method, and by disabling Adjusts Scroll View Insets on any controller, so I don't need this as an answer to solve my problem.
My question is why the content insets are properly set right after the first controller gets loaded from the storyboard the first time, and why they break after any kind of user interaction.
If you need to test it directly, here's a link to the project
I'm not 100% sure it's what you're running into, but here's some explanation regarding your setup:
By default, UIViewControllers tend to be configured to extend their content behind non-opaque bars, and to adjust scroll view insets. In your setup above this means that the container VC:
Extends its content so as to appear behind the navigation bar
Sets its scrollview's .contentInset and .scrollIndicatorInsets to be the same height as the navigation bar
"But, ah!" I hear you say, "that container view controller doesn't have a scroll view". Well this is the tricky bit:
It seems UIViewController's definition of "my scroll view" is rather simplistically, "the first scroll view I come to when searching down through my view hierarchy".
UIPageViewController happens to be implemented using a scroll view. So the container VC finds that scroll view, and adjusts its top insets. This is not really what you want; it confuses the page controller, and tends to upset layout at some point.
The simple solution there is simply to turn off .automaticallyAdjustsScrollViewInsets for the container view controller.
You then need to solve the next problem of your table view needing some kind of top insets to account for the navigation bar. So far it seems to me the best way to do this is manually either in the storyboard, or code.
Found an elegant solution:
From your storyboard, select your UIPageViewController
In the Attributes inspector, uncheck the option ViewController => Extend Edges => Under Top Bars
That's all, no weird UI hacks
Have you tried fixing the Auto Layout constraint in the container view of the Root view controller in the Storyboard (that is, the top space constraint should be set related to the Top Layout Guide and not the Superview, with constant = 0)?
You will only lose the effect of the Table View scrolling under the Navigation Bar

UISegementController in top of UITableView

I would like to add a UISegmentController in the top of my UITableViewController, just like in the AppStore.
I have tried googleing this but either I am search for the wrong things, or too view have written about this.
How can I do this, keeping it in the top with a different design than the UINavigationBar.
For style add segmentCont.segmentedControlStyle=7; which is same as the picture style.
It may not be a UITableViewController. It might be just a UIViewController with a segment control at the top of the XIB and a tableview placed underneath the segment control. That way, you could scroll the table view without scrolling the segment control.
I believe that is a custom header cell for the tableview. You should start by created a custom header with your segmented control inside that.
I think that's a ToolBar with UISegmentedControl or just UISegmentedControl and UITableView under it. You can place them (UISegmentedControl + UITableViewController) on UIScrollView and disable scroll for UITableView. You should make appropriate contentSize for your scrollview.

Resources