I am retrieving 10,000 records from an Ultralite database to an array.
My query is taking 3 seconds load values to the array. This is making the UI to freeze for 3 seconds whenever i click to open the view controller.
I want to open the view controller immediately and show Activity indicator for 3 seconds while my query is executing in background.
And if possible i want to show row animation and show row count like “Number Of Products retrieved is 5045” dynamically.
Please, can anyone help me on this?
Thanks in advance.
EDIT:
NSMutableArray *customerArray = [[DB sharedInstance] LoadCustomerOverview];
The “LoadCustomerOverview” is a function which is having the select statement which retrieves 10,000 records from Ultrlite database.
The above line is taking 3 seconds. I checked this with NSLog before and after above statement. Using this “customerArray” i will fill the UITableview in my view controller,which is taking only Milli seconds to prepare cells.
Problem is with the above line.
How can i solve this problem? or any other way to improve performance?
Thanks in advance.
Accept from all other good answers, this may little different, there’s (mostly) 10-11 for iPhone device and its double in iPad devices (I’m not having exact idea), number of rows visible to users in
UITableView. If you really don’t need to process or show all 10k records at once, I think you really don’t query for all as it takes good memory and processing time as questioned by you. Instead you can fetch (query for) 1k (or even some small amount) of records at once, once you get 1k (or the amount of you want) you can query for the next and that should be in[self performSelectorInBackground:@selector(getRecordsFromDatabase) withObject:];so your app will never freeze & user won’t feel any interrupts, This scenario could only achieve if your data is persistent and having a unique row identifier key (primary key), also if you’re query those data in either ascending or descending order, for other cases like, if you want any random data then this answer can’t work.Also note that, putting code in
viewDidAppear&UIActivityIndicatormay be your solution, but in case you’ll fetching some more amount of rows that time it will interruptable for user.