• 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
TextField not updated in a sheet for document-based Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

TextField not updated in a sheet for document-based Cocoa app


  • Subject: TextField not updated in a sheet for document-based Cocoa app
  • From: Gilles Celli <email@hidden>
  • Date: Mon, 11 Jun 2012 16:29:10 +0200

Hi,

I've written a document-based Cocoa application on OS X which displays graphs visually by opening an ASCII file.

My program has also the possibility to append ASCII files to the current document: when a user chooses the "Append …" menu in the File
Menu a sheet opens with a NSTextField appendingTextField which *should* display the current files (along with a "Cancel" button), and
if the file's matches the current document by comparing some values (date / time / location) etc.

While appending and combining these files together takes some time (can take up to more than 10s)
 the sheet is properly displayed (with its TextField and button) for the current document window, but the textField stringValue can't be set
Maybe because it's the sheet is on a different thread ?…

I've tried to get the sheet's textField string setting on the main queue to allow the update, but this doesn't work either….
Does someone have any clues ?

What I've done so far:

init method:

appendFilesSheet = [[AppendFilesProcessingSheetWindowController alloc]
                            initWithWindowNibName:@"AppendFilesProcessingSheetWindowController"];

Then in:

- (IBAction)appendfFiles:(id)sender
{
	// Open the panel to append files
	NSOpenPanel *openPanel = [NSOpenPanel openPanel];
	[openPanel beginSheetModalForWindow:window completionHandler:nil];
       NSArray *filesToAppend;

    NSInteger result = [openPanel runModal];
   	if (result == NSFileHandlingPanelOKButton)
    {
        filesToAppend = [openPanel URLs];
    }

    [openPanel orderOut:self];
    [NSApp endSheet:openPanel];

    openPanel = nil;  // preventing strong ref cycle
    …
   …..

 NSString *appendedTsoftString;

    [NSApp beginSheet:[appendFilesSheet window]
           modalForWindow:window
            modalDelegate:nil
           didEndSelector:nil
              contextInfo:nil];


	// Combine the files….
	 appendedTsoftString = [[NSString alloc] initWithString:[self combineFiles:filesToAppend withError:&appendError]];

So inside the combineFiles method I try to update the appendTextField
…

 // Update count since we got new append files
    countAppendedFiles = [tsfFiles count];

    void (^appendBlock)(void);

    appendBlock = ^{

        dispatch_async(dispatch_get_main_queue(), ^{
           	[[appendFilesSheet appendTextField] setStringValue:@"Appending Files..."];
            //[[appendFilesSheet appendTextField] setNeedsDisplay: YES];
            NSLog(@"[appendFilesSheet appendTextField] stringValue: %@", [[appendFilesSheet appendTextField] stringValue]);
        });
    };

    //Run the block on a different thread.
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue,appendBlock);
    …


Any help would be 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


  • Follow-Ups:
    • Re: TextField not updated in a sheet for document-based Cocoa app
      • From: Graham Cox <email@hidden>
  • Prev by Date: setting preselected file for nsopenpanel
  • Next by Date: Re: setting preselected file for nsopenpanel
  • Previous by thread: Re: setting preselected file for nsopenpanel
  • Next by thread: Re: TextField not updated in a sheet for document-based Cocoa app
  • Index(es):
    • Date
    • Thread