Tuesday 15 March 2011

objective c - NSFetchedResultsController Freezing UI -


I'm having trouble using NSFetchedResultsController, where I can not stop it from freezing the UI. It is initially quick but when I stop any mistake, then the table gets accumulated when scrolling the view. I am using only 8 elements for testing and using StackMab for my back end.

Here is where I declare NSFetchedResultsController

  - (NSFetchedResultsController *) fetchedResultsController {if (_Fadeed Results Controller! = Void) {Return _ Fetch Result Controller; } NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription * entity = [NSEntityDescription EntityForName: @ Managed object contact in "post": _managedObjectContext]; [FetchRequest Set Entity: Entity]; NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey: @ "created" ascending: no]; [Set FetchRequest SourceScripter: [NSArray arrayWithObject: sort]]; NSFetchedResultsController * theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest Managed ObjectCorrect: _managedObjectContext sectionNameKeyPath: zero cachename: zero]; _Feleted Results Controller = The Fractal Result Controller; Return _fetted result controller; }   

And here is my view deedload:

  - (zero) viewDidoadload {[Super Viewedload]; UIColor * backgroundImage = [[UIColor alloc] initWithPatternImage: [UIImage imageNamed: BACKGROUND_IMAGE_TAN]]; [[View Yourself] setBackgroundColor: backgroundImage]; [[Self tableview] Setshipper style: UITTualWeekal SeparatorTestylonon]; _managedObjectContext = [[self.appDelegate coreDataStore] contextForCurrentThread]; NSError * error; If (! [Display the self-brought results controller]: & amp; Error] {// Update NSLog (@ "Anisolal Error% @,% @", Error [Error to handle error correctly] User Info]); Abortion (); // Fail}}   

And here's my cellphone write index:

  - (UITableViewCell *) TableView: (UITableView *) Table View CellForouaitindPath: (NSIndexPath *) IndexPath {static NSString * CellIdentifier = @ "CCCell"; CCEL * cell = (cccl *) [tableview decomputer reusable cell with identifier: cell identifier]; If (cell == blue) {NSArray * topLevelObjects = [[NSBundle main bundle] loadNibNamed: @ "CCCell" owner: zero option: zero]; Cell = [top level object objectatting index: 0]; [Cell Settleatet: Self]; [Cell setSecurityist Style: UITTWewsSellsStylean]; } Post * Post = (Post *) [_ fetchedResultsController objectAtIndexPath: indexPath]; // // If I UNCOMMENT this line unlocks this UI // / NSLog (@ "% @", [Post Value Forex: @ "value"]); Return cell; }   

Where I am applying the specified line it scrolls very slowly

I have tried to circumvent the call with calls like this

  sending_field_tcardettrad = dispatch_qu_credit ("com.YourApp.YourThreadName", DISPATCH_QUEUE_SERIAL); Dispatch_Associate (CoreDatthread, ^ {Post * Post = (Post *) [_ fetchedResultsController ObjectAttendAxpath: IndexPath]; NSLog (@ "% @", [Post ValueForcowi: @ "Price"]););   

But then it takes a long time 20 seconds or so

< P> Set a fetchBatchSize on your fetched request, the number of the onscreen in your table will be equal to it will save the entire dataset to load cacheName on See also NSFetchedResultsController documentation.

Your [[self.appDelegate coreDataStore] contextForCurrentThread] looks suspicious, by the way. This UI code will be executed on all major threads, so asking for another object is not nearly necessary to build counter-thread MOC.

Your GCD code is incorrect because now you are talking to the main UI thread and your GCD coreDataThread same NSFetchedResultsController , thus two threads one He is talking to MOC.

If you were never surprised by core data performance.

  -com.apple.CoreData.SQLDebug 1   

As a command-line argument enabled through a schematic editor.

No comments:

Post a Comment