iphone - CoreData weird behavior when data are loaded on background thread -


I have a very strange problem, when I do not understand what's going on, I'm looking for clarification this. The situation is as follows:

I have a view controller with scrollwalls in which there are three subwigs. The method in those three sub-methods

  - (zero) Load dialog  

Loads the contents from the database using CoreData in the background thread, which creates a subviews that represents the loaded item and adding them as their own subviews Add: ItemView]; That method is implemented as

  [Self Performance Selector Inboxground: Object with: @ selector (load content); zero];  

I am using a Singleton Service class to load data from DB. Everything is fine, but when these three ideas are loading their part of the data, it sometimes crashes the app.

I guessed it because it shares an NSManagedObjectContext instance for all reading tasks, so I rewrite the class, the stock only creates the NSManaged object model and the NSPersistentStoreCoordinator instance, and this is itself the NSManagedObjectContext instance makes.

Suddenly, very strange thing happened. Data is loaded properly, subviews are created and view is added to the hierarchy, but it is never displayed on screen. When I switch back to the Old Singleton Service Class (sharing a managed object contact), it works again like a charm! (But with the risk of app crash, though).

I do not know exactly how to load data from DB related to displaying items on the screen. More on that - when the subviews are created and the scene is added to the hierarchy, then the hell which does not appear?

The source looks like this:

  - (zero) load content {NSAUTOriaspool * pool = [[NSAUTOriyapul Alok] IIT]; NSArray * Result = [[WLDataService *] [WLDataService Service] loadItemsForGDView]; NSUInteger channelPosition = 0; CGFloat Status = 0.0; CGFloat minuteWidth = ((self.superview.frame.size.width / 2.0) / 60.0); (Item * in the result) {/// The size of the following lines and status of the scene is calculated according to the setup of the item - skipping here .... This UIView class is a simple subclass of WLGDItemView * item = [[WLGDItemView alloc] init]; /// The variables used here are declared above when the size and location are calculated for the object. Frame = CGRactack (itemx, item y, madwidth, itemite); [Self Performance SelectorManaththread: @Selector (Ed SUBUView) with Object: Item Waiting for Donation: No]; /// This is just a helpful macro to issue WL_RELEASE_SAFELY things (item); } [Pool drain]; } The basic service class (non-singleton one) implementation is as follows (interesting part only):  
  #import "WLLocalService.h" static NSPersistentStoreCoordinator * Shared PSC = Zero; Fixed NSManagedObjectModel * SharedMom = Zero; @ Implementation WLLocalService @ synthesis managed object contexts; /// This is here for backward compatibility reasons (WLLocalService *) service {return [[all alloc] init] autorelease]; } #pragma mark - #pragma mark core data stack - (NSManagedObjectContext *) managedObjectContext {if (managedObjectContext == blue) {NSPersistentStoreCoordinator * coordinator = [self-sustained store coordinator]; If (coordinator! = Zero) {managedObjectContext = [[NSManed object contact alloc] init]; [ManagedObjectContextSetsConstantstoreCodernet: Coordinator]; } [ManagedObjectContext setUndoManager: noil]; [Managed object contact set margin policy: NSMERJPTPTORRRMMRGPCBC]; } Managed object contacts in return; } - (NSManagedObjectModel *) Managed object model {if (sharedmom == zero) {sharedMOM = [[NSManAdd objectModel merged modulefeed bundle: zero] has been maintained; } Returning shared MOM; } - (NSPersistentStoreCoordinator *) Continuous store coordinator {if (shared psc == zero) {NSURL * storeUrl = [auto datastopath]; NSError * Error = Zero; Shared Psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [Self-managed object model]]; If (! [Share PSC addPersistentStoreWithType: NSSQLiteStoreType Configuration: Zero URL: Store URL Option: Zero Error: & Error]) {WLLOG (@ "% @:% @", Error, [Error User Info]); }} Back share psc; } #pragma mark - #pragma mark Path to the data store file - (ns URL *) Datastopath {Returns [NSUr File URL Along Path: [WL_DOCUMENTS_DIR (stringBapping path comparison: @ "/ dB.sclient"]]; } - (zero) Deloq {WL_RELEASE_SAFELY (Managed Object Model); [Super DeLoc]; } @ And  

I would love to know what is happening here and why it behaves strangely (and of course - why does this work, especially)

have you read twice?

/ P>


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -