Reputation: 1299
I have a UITableView in which each row of tableview has uicollectionview data. The problem I am facing is UITableView has around 800-1000 rows and then each row has almost uicollectionview cells of around 200-400.
When I start scrolling the uicollectionview and/or uitableview it gets slow, and sometimes crash because of memory warning.
I understand this reason because of large data. But I want to know the best method how i can dynamically load and unload data so that it never gets memory error and never gets slow.
Please suggest.
Thanks
Upvotes: 0
Views: 327
Reputation: 13302
I will definitely recommend to use paging for both UITableView and UICollectionViews that are placed inside table.
Good practice is preload only 10 - 20 elements. If user scrolls to the end of the list, app loads next page (10 - 20 elements).
In your case it will be two types of paging:
1. Vertical paging for UITableView.
When user scrolls down to the end of table list, app will load data for next 10 table cells. Every cell will load data for 10 items for collection view that is inside of cell.
2. Horizontal paging for UICollectionView.
When user scrolls right to then end of collection list, app will load data for next 10 collection cells.
In most of cases user will not load many pages, so animation will be smooth, and it will not crash.
For that less cases when user still loads hundreds of rows down and right, you can implement method - (void)didReceiveMemoryWarning
in view controller. In this method you can free heavy data (images, videos) that related to cells that are not presented currently on the screen.
Upvotes: 1
Reputation: 5326
Maybe you can load the data only of the presented cells only when the table is not scrolled, and prevent load the data for cells when the table is scrolled. (Check the scroll view delegate functions, it may give you the indication of scrolling and decelerating of the table).
Upvotes: 1