I have a UITableView inside of a UIScrollView.
While this isn’t ideal, it was “necessary” since I wanted to put another custom view on top of the table, which is scrolled off using the scroll view. The table view is used in many different parts of my app and would be great to keep it encapsulated and reusable.
The problem now is that because I no longer utilize the scrolling of UITableView itself (it is sized big enough to display all its cells, and then placed inside the scroll view), I lose the on-demand loading of cells. This makes for unacceptable performance when my table view has more than a few cells.
What is the best way to set up something like this without losing dynamic cell loading?
The only way I can think of is making the whole thing a table view, and making my top custom view just another cell. But this would mean I can’t as cleanly reuse my UITableView.
As long as your tableView is inside a scrollView, you’ll have this problem since the whole tableView has to be drawn, and hence all the cells have to be allocated.
What I suggest is to add the view as a header to your tableView using
– tableView:viewForHeaderInSection:and– tableView:heightForHeaderInSection:in yourUITableViewDelegate.This won’t be quite as clean just putting the tableView inside another view, but it shouldn’t be as bad as implementing the additional view as a cell, since you won’t have to mess with methods like
cellForRowAtIndexPath:.