Loading cells on demand in a UITableView in a UIScrollView

I have a UITableView inside a UIScrollView.

While this wasn’t perfect, it was “necessary” since I wanted to put another custom view on top of the table, which scrolls by scrolling. The table view is used in many parts of my application, and it would be great to keep it encapsulated and reusable.

Now the problem is that since I no longer use the scroll of the UITableView itself (it is large enough to display all its cells and then placed in the scroll), I lose on-demand load cells. This makes performance unacceptable if there are multiple cells in my table view.

What is the best way to configure something like this without losing the dynamic loading of cells?

The only way I can think of is to make it all a table view and make my own custom view just another cell. But that would mean that I cannot reuse the UITableView as cleanly as possible.

+4
source share
2 answers

As long as your TableView is inside scrollView, you will have this problem, since the entire tableView must be drawn, and therefore all cells must be selected.

I suggest adding a header view to tableView using – tableView:viewForHeaderInSection: and – tableView:heightForHeaderInSection: in a UITableViewDelegate .

It will not be so simple by simply placing the tableView in another view, but it should not be as bad as implementing an additional view as a cell, since you do not have to bother with methods such as cellForRowAtIndexPath: .

0
source

OLEContainerScrollView seems to be a solution.

Which allows you to add several UIScrollViews (UITableView, UICollectionView) to it, however, support the cell reuse mechanism on the internal UITableView, UICollectionView.

-one
source

Source: https://habr.com/ru/post/1397976/


All Articles