views:

158

answers:

0

I am using a modal sheet to edit a certain data entity. This sheet is run as application modal. When the sheet is launched, the object controller in the same nib as the sheet is set to the currently selected NSManagedObject.

The code leading into the launching is as follows:

[objectController setContent:object];
[NSApp beginSheet:[self window]
   modalForWindow:modalForWindow
 modalDelegate:self
   didEndSelector:nil
   contextInfo:nil];

This seems to work mostly. However, there is a bug. Clicking on the sheet ui button launches the sheet but the data being displayed is wrong. If I subsequently close the sheet, and launch it again, the data is now right but only displaying the previous selection. And from that point on, the displayed data is always "lagging by one click".

I've also tried to go through the coredata context and send a fetch message to the NSObjectController, but this results in essentially the same problem.

The fetch documentation does say that the operation is carried out on the next available NSRunLoop iteration (quoting: Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.).

I've tried spinning the loop using:

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];

or alternatively, setting the object, and then queuing the beginSheet on the run loop like so:

[[NSRunLoop currentRunLoop] performSelector:@selector(beginSheetDelayedImp:)
   target:self
    argument:modalForWindow
     order:0
     modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];

All to no avail. Any ideas?