Re: TextField not updated in a sheet for document-based Cocoa app
Re: TextField not updated in a sheet for document-based Cocoa app
- Subject: Re: TextField not updated in a sheet for document-based Cocoa app
- From: Gilles Celli <email@hidden>
- Date: Wed, 13 Jun 2012 23:18:36 +0200
Graham,
Following your suggestions I tried with [[NSOperationQueue mainQueue] addOperationWithBlock: to update the textField while processing files....but with less or more success...
While I put [NSApp beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: inside [[NSOperationQueue mainQueue] addOperationWithBlock: the sheet window is not loaded directly...it displays after some file processing has been done ...
1. First I put the [NSApp beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: ... before processing the files
(this consist on reading the ASCII files with initWithContentsOfFile: then extracting every channel with NSScanner, this can take up to 2-10 seconds depending on the file size).
First problem:
The sheet with the textField is not displayed directly after the openPanel (to select the appended files) is closed...
This is as you suggested due to the fact that the sheet's window has not finished to load...so how do I invoke windowDidLoad for appendFilesSheet (NSWindowController)...
2. While processing the files the textField is only updated after the whole process has finished...this is not what I expect...would
be nice to update the textField by showing which file it actually processes etc.
I put again the whole code inside NSOperationQueue mainQueue block:
// Do some basic processing...
// Compare the appended files location name with the original's document file location and update the sheet's textField
// Some pseudo-code hereā¦
for (int i=0 ; i < numberOfFilesToAppend; i++)
{
NSString *nameOfLocation = [[asciiFilesToAppend objectAtIndex:i] locationName];
....
....
if [nameOfLocation isEqualToString originalLocationName]
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^(void) {
NSString *stationLocation =
[[NSString alloc] initWithFormat:@"Location of the instrument location:%@", [asciiFilesToAppend objectAtIndex:i] stationLocation];
[[appendFilesSheet appendTextField] setStringValue:stationLocation];
[[appendFilesSheet appendTextField] setNeedsDisplay:YES];
[stationLocation release];
}];
}
}
But no luck...the appendTextField is only updated after the whole process has finished...showing only the last object's name
I'm pretty sure I'm doing something wrong here...so any clarification, or suggestions is of course greatly appreciated ;-)
Cheers,
Gilles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden