Re: Core Data: Progress bar using Sheet, modifying context in thread
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