1

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.

4

5 に答える 5

0

I can't imagine why would you need 10000 records in an array, as this can probably be optimised.

However, to answer your question, you could move your loading method to viewDidAppear: (I'm assuming you're doing your fetching in viewDidLoad:), and bring up some sort of a progress bar before you start the load.

于 2012-10-22T10:18:46.973 に答える
0
[NSThread detachNewThreadSelector:@selector(startBackgroundProcess:) toTarget:self withObject:YOUR_OBJECT];

-(void)startBackgroundProcess:(id)obj{
//interact with DB..
//After firing the query and get the Data 
[self performSelectorOnMainThread:@selector(finishedBackgroundProcess:) withObject:YOUR_RESULT waitUntilDone:NO];  
}
于 2012-10-22T10:19:13.467 に答える
0

Solution is performSelectorInBackground which will not freeze your UI

[self performSelectorInBackground:@selector(getRecordsFromDatabase) withObject:yourObjectHereAsArgument]

Now method:

-(void)getRecordsFromDatabase
{
  //retrieve records here
}
于 2012-10-22T10:25:35.423 に答える
0

Update: Do you use Core Data ? What if you batch ? [fetchRequest setFetchBatchSize:20];

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSFetchRequest_Class/NSFetchRequest.html

Regards,

于 2012-10-22T10:26:09.243 に答える
0

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 & UIActivityIndicator may be your solution, but in case you'll fetching some more amount of rows that time it will interruptable for user.

于 2012-10-22T12:41:07.230 に答える