Insets around section of UITableView - ios

Is there a way to give spacing around a section? I know this can be done using UICollectionView. Have implemented all the things using UITableView and UITableViewCells, don't want to move things to UICollectionView.
I am trying to achieve space around the section(all sides) to give a group kind of feel for section(including header, cells and footer views).

You can use tableView(_ tableView: UITableView, viewForFooterInSection section: Int) and tableView(_ tableView: UITableView, heightForFooterInSection section: Int) to add more space between sections without messing with margins.

There is no straight forward api for this.
Add some space on every side of UI elements which you have added on top of section header view. eg. (10,10,width,height)
Apply same gap for Cell subviews as well.

If you created your table view section header via IB, you should add the one more UIView object before doing anything else. Then, you have to add correct constraints to this view relative to the header content view. I think you will add your margins from each side. Then you should adjust your table view background colour. Now I think you are free to make something like you described

You could actually use the tableView separator inset, with the separator style of none, and That's it!
I know it's a bit late but hopefully the answer could be of use for others.

Related

Expandable UITableView with moving rows between sections buggy footer problem

I am trying to make an expandable tableview. Here I didn't use headers and made all of those section stuff using rows. In here I've found a bad behaviour that blocks my move operations. As you see in gif, i added height on footer sections to show what is really happening. I don't want any border in my application between sections. As you see, I want to move rows into upper section if it is upper than 'Done' section text. How can I achieve those purpose?
Problem Demo: https://i.imgur.com/VIMf5sb.gif
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
print(sourceIndexPath)
print(destinationIndexPath) }
In the buggy situation destinationIndexPath section is 2 and row is 0. So I believe my code does not contain any code error. How can I fix that UX problem when there is no border between sections?

UITableViews inside UIScrollView

I have read a few posts asking about to put UITableViews inside a ScrollView but mostly this idea is not recommended. The "standard way" to handle this situation as I understand is to use just the UITableView instead of the ScrollView and make the TableView header the UIView to display the content and to use the cell to display any dynamic rows.
However the app I am now developing is a bit different: the first part of the view is some descriptive content that I can use the header view to display. But after that I want to display two scrollable sections potentially with dynamic height. One is a comment section displaying all comments and replies and another is a user section that display any users ever made an offer. This two sections need to be row-based and will be dynamic in height as the content inside them will be different.
So the question is, how should I implement this without putting two UITableViews inside a UIScrollView(My original plan)?
UITableViews inside a ScrollView is not at all recommended as UITableView as its own scrollView as subView.
This two sections need to be row-based and will be dynamic in height
as the content inside them will be different.
Whats wrong with using the delegate for dynamic height for row
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {}
Some Tutorial:
https://www.raywenderlich.com/129059/self-sizing-table-view-cells

Swift: How to create space around cells in a static UITableView

I am trying to create a gap between my cells in a static UITableView. The UITableView has 3 sections, each containing 2 rows. I have tried
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 15
}
but this method does not seem to work.
This might be a little bit of a hack but it has worked for me in the past.
Simply add a UIView to the UITableViewCell and set it as a different background colour to the UITableView.
If you make the UIView smaller than the UITableViewCell, you will be able to get the desired spacing just by adding constraints.
I hope I've understood the correctly
This isn't something that UITableView does by default. There isn't a simple way to add spacing between cells, that's generally something you'd accomplish by using a UICollectionView.
If you have to use a table view you can try adding the padding into a custom UITableViewCell itself, which will create the affect you're looking for. You could also try adding additional "spacer" cells that go in between your primary content cells.

Prevent UITableViewCell from scrolling under viewForHeaderInSection

I have a fairly complicated UIViewController with a custom UITableView instantiating on top of a Visual Effect & UIImageView. In order to keep the beautiful blur effect throughout the UITableView, I had to set the entire thing's background color (including UITableViewCells and viewForHeaderInSection) to UIColor.clearColor(). The obvious problem (that I can't solve) is that when I scroll up, the text of the UITableViewCell will scroll under the clear background of the viewForHeaderInSection and both text will overlap. Here's a screenshot.
Any thoughts on how I can prevent the UITableViewCell from scrolling under the viewForHeaderInSection? I was playing around with the UITableView's contentInsets but that changes the entire UITableView, not just the UITableViewCell sections. Thx in advance...
1) Select the tableview in storyboard.
2) Select attribute inspector.
3) Change the style from plain to grouped.

UITableView footer doesn't locate correctly

I want to keep the footer of my UITableView float.
I did it correctly, but my problem is that, the footer doesn't show all, I have to scroll a little bit to see it, I don't know why.
look please, the footer just shows the top black, not the down black one:
Where I do have in the interface builder both top and bottom black bar
I add the footer easily like this:
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return self.footerView
}
The height of the footer is managed by the delegate method heightForFooterInSection. You need to pass the correct height of your footer in this method to show the footer completely.
Seems like height of footer in your implementation is cut off slightly. Make a try after increasing the height by 20 px.
A section footer view can "Float" only if your tableview style is "UITableViewStyle.Plain" , otherwise you need to implement a custom "Floating" View above your tableview by your self.
Set height of your tableview correctly. Your table view is going a few pixels down the screen. Setting tableview height will resolve the issue
The footer from the running app and from the storyboard looks different. The one from the app is rounded. Is there any chance there are two footers and you are using the wrong one?
Also you should provide some other information from your storyboard. Some images of your tableview properties for example. I think you are using autolayout. You can't get satisfying answers without these info.
Also you can check this answer for misplacement of your tableview. https://stackoverflow.com/a/27527905/697467

Resources