Table view header, storyboard, Xcode 11? - ios

In XCode 11,
new storyboard,
add a UIViewController (sic: NOT a table view controller),
hit the + symbol top right,
drag a table view into the view controller.
Perhaps add four constraints so it is simply full-screen.
Table view attributes inspector, perhaps set Prototype Cells to not-zero, say 2.
How do you now add a header view to the table view?
(The header view should (obviously) be able to handle dynamic height content.)

The easy way of to achieve adding HeaderView to UITableView is.
Plus + button from Top Bar and Select an UIView
Then in hierarchy add the exact bottom of the UITableView.
See the image.
Your UIView element must be like that in the hierarchy.
Then the UIView calculations for dynamic view upon to you.
(You can create an IBOutlet of the this UIView and do some calculation in your UIViewController. )

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.

Adding a fixed-position view on top of a view

I have a UITableViewController inside a UINavigationController. I'm adding a "modal" subview to the tableView, which is a custom UIView when one of the rows is selected.
(It’s modal in spirit, not in the UIKit sense, since Apple doesn’t support modal views on iPhone, I’m adding it with a [self.view addSubview:customView] in my table view’s controller.)
I would like it to appear at the bottom of the screen and stay put there. I can get it to draw at the bottom, but once I scroll the table view, the view moves with it. Here are some illustrations:
Initial position (good):
Position after scrolling (bad):
I'm getting the bottom position by subtracting the height of all the chrome (navigation bar and status bar) as well as the height of the custom view from [UIScreen mainScreen].bounds.
How can I get the custom view to stay put? Should I constantly be adjusting its frame when the table view is being scrolled?
Your best and most flexible option is to switch to using a view controller with the table view as a subview so that you can change its frame and add sibling views. Then, when you want to add a modal you can run an animation to move the table view out of the way and slide the modal view in.
UITableViewController.view is an instance of UITableView. Means you added your custom view into a scroll view and that is why it scrolls. You can try to put your custom view into the tableFooterView property of the UITableView, which is the old school solution.
Personally I would create a container UIViewController and have UITableViewController be a sub viewController of it. Another sub viewController UIViewController or just a simple UIView could represent the footer.

How to add buttons and search bar into header at top of UITableViewController?

I have a search bar and some buttons in a view in my UITableViewController, but I don't know how to make that view the header? I've attached the referencing outlet to the UITableController. But currently the search bar and buttons scroll up and down with the tableview, but I want them to be the header so they stay fixed.
Here's a screen shot of what I currently have...
ok I ctrl/dragged from the view to my ViewController and created a IBOutlet, as you can see in this next image, and I added in the line to set it to be the header but it seems to give an error??
The easiest solution would be to move that view containing the search bar and buttons to being a subview of the view controller's view instead of inside the table view. Then apply your constraints so that it is pinned to the top and the table view is constrained to the bottom of the view.
If the list of elements you are displaying do not have more than one section, then you could implement the tableView:viewForHeaderInSection: delegate method. Create the headerview containing the searchbar in storyboard and return the instance. It will be always on top of the list.
Apple Documentaion

change position and layout of table view and table view cell for iOS app in Swift

I have created a table view controller with a table view cell for my iOS app with storyboard in Xcode 6. In the cell I have an image and a label. At the top of the view controller I want to have a header and at the bottom I have a tab bar. That's my setup.
But now I want to change the position and the layout of the table view and the inherit cells, default they cover the whole screen. The table view should start below the header and should end above the tab bar. At the moment the cell content is displayed under the headline and the tab bar. Is it possible to set the positions of the table view and/or cell? And also I want to change the layout of the cells. I want to have some space between two cells and a corner radius.
THX!
This is an old "problem". If you want to use a UITableViewController, the table view will cover the whole screen. In fact the UIViewController's view property will be the table view.
If you want to have a table view and other views on the screen, you will have to use UIViewController and add two subviews to it's view: the header and the table view.
Do the following (which the UITableViewController would have done for you):
add the table view as an ivar;
have the class conform to UITableViewDelegate and UITableViewDataSource and
set it to the table view's delegate and datasource

How do I add a footer to a UITableView using Storyboard?

Same as this question, only the proposed solution doesn't work for me. When I drag a view to the bottom area of a tableView, it tries to add it to the list of cells higher up:
I'm sure I'm missing something simple... I'm new to storyboards.
EDIT:
Maybe it is adding a "footer" (though, it doesn't label it as such), it's just not adding it low enough. I was ultimately hoping to add an item that would appear at the bottom of the screen (and stick to the bottom of the screen).
TIP: You can use the Tree view (outline view) on the left to arrange the Views (and sub views). I have done a lot of storyboard editing, and dropping things into table views rarely go to the correct hierarchy level in the tree view.
Create a New UIViewController
Insert a UITableView
Resize the tableview by dragging its dimensions
The attached picture has a UITableView on TOP of a UIViewController's UIView. Make sure that you set the delegates in the UIViewController's .m, assign the tableView as a property of the view controller, and then set the tableview's delegate property to the UIViewController object. i.e.: tableView.delegate = self or [tableView setDelegate:self]; also with datasource.
OR you can just click the tableView, on story board, and then drag its delegate and datasource property to THE UIVIEWCONTROLLER! not the view! You can do this by dragging it to the this highlighted part of the view controller's toolbar on the storyboard:
Either you can create a footer view programatically or you can load a view from UIView outlet
UIView *tempFooter=[[UIView alloc]initWithFrame:self.Footerview.frame];
[tempFooter addSubview:self.Footerview];
self.ItemDetailsTable.tableFooterView=tempFooter;
self.Footerview //View outlet
You need to set all the needed constraints of the self.Footerview to get the required layout of the footer view.But you don't need to set constraints for tableview footer itself.

Resources