How to prevent section from scrolling when dragging cells? - ios

I want sections would have same behavior as cells when I drag it.
Usual behavior is — when dragging cells, section stands on a same place until it meets other section.
What I want is section drags as usual cell.

The following is from the UITableView Class Reference
Table views can have one of two styles, UITableViewStylePlain and
UITableViewStyleGrouped. When you create a UITableView instance you
must specify a table style, and this style cannot be changed. In the
plain style, section headers and footers float above the content if
the part of a complete section is visible.
If you are going to use the UITableViewStylePlain, I am not sure you can re-engineer the section headers to not float.
An alternative is to use the UITableViewStyleGrouped or use UITableViewStylePlain and instead of using sections, you could separate out your table view by placing the section as another cell.

Related

How to disable the scrolling of table view for first Section #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
}

Can we add tableview to cell?

I want to customize my tableview. I want to add another tableview in cell. Can we add tableview in cell of another tableview?
Please give me some ideas.
You can embed a UITableView into another UITableView's cell, but due to potential issues with the embedded UIScrollViews it is not recommended.
If you feel like you need a table in a table, first consider if it is not possible to achieve the desired behavior by using sections and cells in the sections (a section in a table might represent the top tableView's cell, and cells in the given section would represent the embedded tableView's cells).
There is no problem with adding a UITableView into a a UITableViewCell, since both of them are UIViews its simply would be translated to adding a subview to a view...
However, keep in mind to consider the following issues:
1- From a user experience perspective, that would be a vertical scroll view inside another vertical scroll view (are you ok with that?).
2- For each cell -in the main container table view-, you would need to handle the table view delegates/datasources. For understanding the logic of how this could be done, you might want to check:
Is it possible to add UITableView within a UITableViewCell.
Putting a UICollectionView in a UITableViewCell in Swift: although it is about adding a UICollectionView inside the cell, it helps to gain the logic of how to achieve such a task.

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.

iOS - Sticky section headers in grouped UITableView with custom cells

I noticed that when using custom cells in a grouped UITableView, the section headers no longer stay at the top of the view when scrolling down. They just pass out of the view like the rest of the cells. Is there a way to keep the default behavior of the headers while using a custom cell?
grouped style never stays at the top, plain does.

Single Header View at top of UICollectionView with multiple sections

I understand how to include a header view per section, but how do I go about having a single header view at the top of a UICollectionView with multiple sections? I just want a view that sits on top of the collectionview that scrolls with the collectionview.
I've looked into decoration/supplementary views..but I think I can also just make it a new section with a single cell. What is the best practice for this?
Not sure if this is "best practice," but I ended up creating a section at the top with a single cell. I looked into supplementary views, but it seemed like those were primarily used as section headers and footers. New section at top with single item worked well for my purposes.

Resources