• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data: Progress bar using Sheet, modifying context in thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: Progress bar using Sheet, modifying context in thread


  • Subject: Re: Core Data: Progress bar using Sheet, modifying context in thread
  • From: Bill Coleman <email@hidden>
  • Date: Fri, 4 Aug 2006 19:32:16 -0400


On Aug 4, 2006, at 5:12 AM, Andreas Mayer wrote:


Am 04.08.2006 um 06:05 Uhr schrieb Bill Coleman:

since once you call beginSheet: modalForWindow: ..., you can't do any more processing.

Why not? Did you try?
The user will not be able to interact with the parent window. But beginSheet:... returns immediately, so you can start your import after putting up the sheet. Of course, doing the processing in the main run loop will block the application ...

I had something similar to this before I tried to create the sheet. Doing the processing in the menu action method prevents the application from processing any further events. I want this process to be document-modal, not application modal.


I create new rows for import by calling [NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]. I add the object to the NSArrayController by calling addObject:.

Don't. Use only one of these methods.

OK.

It's not necessary because you *already* added the object. NSArrayController will do the insert itself if you send it an addObject: message.

This is not entirely clear from the Core Data documentation.

My question is -- is there any way I can turn off this update of the NSTableView until I'm done?

Yes. Remove the table view's binding to the array controller.

AH! Excellent.

Probably. Did you read this?
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ Articles/cdMultiThreading.html

I scanned this.

My progress bar also seems to jump back and forth a bit, even though I'm steadily increasing the value passed to setDoubleValue:, and I don't change the maximum value after the import starts.

I haven't seen this problem. Show some code.

OK, here's the thread method:

- (void) doImportADIFFromFile: (NSMutableString *) filename
{
	NSAutoreleasePool * pool = [ [NSAutoreleasePool alloc] init];

	NSString * importString = [NSString stringWithContentsOfFile: filename
		encoding: NSUTF8StringEncoding error: nil ];

[progressBar setMinValue: 0];
[progressBar setMaxValue: [importString length] ];
[progressBar setDoubleValue: 0 ];

int pos = [importString skipHeader];

[progressBar setDoubleValue: pos];

Contact * contact = nil;
while ( pos < [importString length] )
{
pos = [importString readContact: &contact fromPosition: pos usingContext: [self managedObjectContext] ];

if ( contact != nil )
{
[progressInfo setStringValue: [contact name]];
}

[progressBar setDoubleValue: pos];
}


[self performSelectorOnMainThread: @selector(endProgressSheet) withObject: nil waitUntilDone: YES ];

[pool release];
}


The above was edited slightly for brevity and clarity. The skipheader and readContact methods are categories added to NSString. (Categories are COOL!)

Bill Coleman, AA4LR, PP-ASEL        Mail: email@hidden
Quote: "Boot, you transistorized tormentor! Boot!"
            -- Archibald Asparagus, VeggieTales

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Data: Progress bar using Sheet, modifying context in thread
      • From: PGM <email@hidden>
References: 
 >Core Data: Progress bar using Sheet, modifying context in thread (From: Bill Coleman <email@hidden>)
 >Re: Core Data: Progress bar using Sheet, modifying context in thread (From: Andreas Mayer <email@hidden>)

  • Prev by Date: Re: Core Data: Progress bar using Sheet, modifying context in thread
  • Next by Date: Re: Core Data: Progress bar using Sheet, modifying context in thread
  • Previous by thread: Re: Core Data: Progress bar using Sheet, modifying context in thread
  • Next by thread: Re: Core Data: Progress bar using Sheet, modifying context in thread
  • Index(es):
    • Date
    • Thread