How to disable the scrolling of table view for first Section #iOS - ios

I have two sections in my table view , I want to have scroll enabled for 2nd section and disabled for 1st section , how could I achieve it ?

A UITableView as a whole is a ScrollView so there is no way to only scroll one section. I'd suggest moving what is in the first section into a UIView, then placing a UITableView below that UIView that just has a single section that contains the views you had in the section of the view.
This way the top part will not scroll, but the bottom part will.

A way to workaround it is having 2 UITableViews, one with scrolling disabled while the other has it enabled.
You can disable scrolling on a UITableView on the Attributes inspector while it's selected. There's a whole section on the Scroll View the UITableView has, and in the second subsection there's a toggle for "Scrolling Enabled" which is on by default.
[Edit: I've just seen the other comment, and I'd still recommend 2 UITableViews if you are dealing with dynamic content. If the content from the 1st section isn't dynamic, you may use an UIView as it'll save a lot of time just by not needing to implement 2 UITableViews in a single UIViewController]

#vinay
Try this solution
Take a view at the top of view controller.
Below that view take tableview.
Set table style to Grouped. It makes sections of tableview scrollable.

In your case I would use Section Header for the second section and make that header as customView.
You need to call the following functions:
1) viewForHeaderInSection
if section == 2 {
... customize your header view
}
2) heightForHeaderInSection
if section == 2 {
... set height
}

Related

How to make section header anchor to the top of a multi section tableview?

I know if set the tableView's type to "Plain" , the section header will automatically anchor on the top of the tableView. but if I have multi sections in the tableView. When the tableView scroll to the next section ,the first section's header will disappear. I hope the first section's header can always anchor on the tableView's top whatever I scroll the tableview to any section. is there any way to do that?
What you describe does not happen for UITableViewStyleGrouped but for UITableViewStylePlain.
I can't really think of any easy way to do what you want - I suspect you'll have to insert your own subview and manage its position according to the table's scrolling position.
I found this article which might have some good ideas for what you're trying to do.

One section of the view controller is still and one section horizontally scrollable

I would like to construct a view controller where one section of the view controller would be still and one section scrollable.
Both sections have headers where as well, one is still and one is moving along with the content in the section.
I do not want the cells in the section to be scrolled separately. All cells should move at the same time along with the header.
I have added an image to make my point little more clearer.
Use UICollection View for both view and disable scrolling for one view and enable scrolling for another view
you can probably add to your UIViewController view a UITableView on the left with fixed size (for example 150px) and vertical scroll disabled and a UICollectionView with horizontal flow and ,if needed a, with custom UICollectionViewLayout (but i think that you just need the classic UICollectionViewFlowLayout) for the right part that fits the remaining space.
Here you can find the component's documentation:
https://developer.apple.com/reference/uikit/uicollectionview
https://developer.apple.com/reference/uikit/uitableview

Two UITableViews in one scrollview

I want to make UIViewController, which has 2 UITableViews - one is content tableview, second is an comments section tableview.
Basically, It's an detail product VC, which has own UITableView for own content and second UITableView will be CommentsVC tableview.
Problem is that, I want to get them like one whole tableView (scroll together) (like 2 section style).
My first idea was to create UIScrollView container, which contains both UITableViews, but I think that there will be problem with reusing cells.
Example sketch
When you take tableview inside scrollview it creates problem in scrolling i.e conflicting scrolls of both scrollview and tableview as UIScrollview is superview of UITableView .
So it's better to take one UITableView with different section. One Section for your content and another section for comments.

can I fix section header view not in the top of UITableView

We know that a plain UITableView will fix its section header view in the top of it. Can we make the section header view not to float in the top of its UITableView, but fix in another position, such as 100 points away from the top of its UITableView?
Any ideals will be appreciated,thanks.
You can add custom view as header to your table view & set the position of tableview from it below 100 points.
Sorry there is no any way to stop it.. But You can do this kind of functionality using the UITableViewCell... take the first cell of section to show section detail and set section height as 0..

Making section in UITableView closed(with 0 cells) after scrolling away and returning to it

I have a UITableView where I have section headers that can be tapped to expand or collapse the section. In my particular example each section only has one row, which is either visible (section expanded) or hidden (section collapsed). (I have a UITapGestureRecognizer on the section headers which I use to expand or collapse the sections) here the process of my actions:
I'm tap on the section (this is UITableViewHeaderFooterView custom view) and i see the cell that appears under the section header. At this moment everything is going OK. But when i scrolling down my tableview, cell goes behind header (like in Contacts application , header is first letter of contact). And finally when i scroll enough to don't see that section with that cell on, and when i scroll up - to return to my display that section - i want to make this section automatically known that when i return(from scrolling away that section from view) to it - i want that section already was closed with 0 cells in it.
Maybe i must use -(void) prepareForReuse at my custom UITableViewHeaderFooterView, or scroll methods ? or any tableView methods?
Thank you
You can implement the scroll view delegate methods and use them to check the scroll position (contentOffset) and / or the visible cells (indexPathsForVisibleRows). Once you know that you can collapse any sections that are no longer visible. You should probably use one of the scroll methods that means the scrolling has stopped (maybe scrollViewDidEndScrollingAnimation:) because changing the table view content size (which changing the number of rows will do) during a scroll animation could cause it to stop abruptly.

Resources