Populating UITableView with data

First of all, although I have an understanding of some of the basics, I am still a beginner.

I have a partitioned one UITableView

that I currently use NSDictionary

(for grouping) and 4 or 5 different NSArrays (for data, some of which is passed to the next view when a cell is selected) to populate the table. This works, but it is a very long list, and after a few minutes of scrolling UITableView

up and down, leaving this view and returning to it, the application starts to "slow down" and eventually freezes. I did some research and found that the way I do it is not the best. I read about using another object to populate the table, which will only load data as needed and will not keep that data in memory (which is probably causing my application to hang).

Can anyone help guide me in the right direction to create a "data object" to store my data and then use it in mine UITableView

? Can I just take mine NSDictionaries

and NSArrays

and somehow put them in my class and call that class? Will I be using master data? Any other suggestions? As a side note, this data cannot be added, updated or removed by the user. The only time I change the data is to add more data (a completely new entry) to make the list longer and maybe occasionally, but very rarely, be updated or deleted by me.

Any help would be greatly appreciated.

+2


source to share


1 answer


It is true that UITableViewController is most efficient when combined with CoreData strong>. For this you need to look in NSFetchedResultsController. If you want an easy way to log into CoreData, use MagicalRecord . It is very easy to use and very effective.

It's worth noting, however, that an NSDictionary with multiple NSArrays populated with thousands of NSStrings shouldn't cause memory issues. The fact that you can load this into memory in the first place assumes that you can store the entire data structure in memory. The fact that you are slowing down and freezing while scrolling means that the memory issue is originating from the UITableView cell instance.



Here are a few things you should check:

  • Do you know how to use the tools? If so, check for memory leaks.
  • Are you didReceiveMemoryWarning

    getting in your UITableViewController? I think so. But you want to make sure that this is not a thread blocking problem.
  • Are you using images in UITableViewCells? If you have thousands of images, you definitely want to use NSCache to store it. This will automatically clear memory when needed.
  • Are you using custom UITableViewCells? Since you are experiencing scrolling slowdown, make sure the custom cell has no drawing problems.
  • Make sure you deactivate the cells. This is done in the UITableViewController template, but you may have removed it for some reason.
0


source







All Articles