I want to display a list of items (sometimes more than 1000), and each list item will display several bits of data from a specific record on a SQLite database. I'm not quite sure how to go about it, as I could either:
a) retrieve the data directly from the SQLite database on every invoke of tableView:cellForRowAtIndexPath:
b) on the viewDidLoad: method of the table view controller, load all of the records into an array of objects holding just the information needed to display the cells.
I'm not sure which one is best because I'm not sure if method A will be too slow over time having to run queries every time a row needs queuing (especially if the user flicks the table view fast), and B may take up a lot of memory, especially when there is lots of data per row and thousands of rows.
One additional constraint is that I will eventually need to have a search box on the table view. Will this affect the decision?
I'm hoping that I could get some tips from anyone with more experience!
There is nothing much you can do. It's iPhone. You only have a few MB of physical memory to create the whole application. Consider for example using UIScrollView with UILabels put inside it as your cells.
Hi All,
What i do is create an array and store just the primary key of the records from your SELECT statement. Then, you basically have an integer array. What you do is on every cell, simply load the cell with the data from the primary key. I call a function that I pass in the primary key and it returns and object of the record so I can pick and choose which data I want to display. Since the array is only holding numbers, memory management is very good even with hundreds of records. Give it a try!
Dave
iPhoneToot.com
Quote:
Originally Posted by XCHG
There is nothing much you can do. It's iPhone. You only have a few MB of physical memory to create the whole application. Consider for example using UIScrollView with UILabels put inside it as your cells.
Hi All,
What i do is create an array and store just the primary key of the records from your SELECT statement. Then, you basically have an integer array. What you do is on every cell, simply load the cell with the data from the primary key. I call a function that I pass in the primary key and it returns and object of the record so I can pick and choose which data I want to display. Since the array is only holding numbers, memory management is very good even with hundreds of records. Give it a try!
Dave
iPhoneToot.com
Thanks for your help.But I don't know how to invoke a method before viewDidLoad?I have written my select query code in one method.Please help me.
Thanks
Thanks for your help.But I don't know how to invoke a method before viewDidLoad?I have written my select query code in one method.Please help me.
Thanks
Try viewWillLoad in the documentation, or put the select query code in a seperate file (.h and .m) and then load it when you need it, say in the appdelegate (I know, I know -- this is not advised)