Hi,in my app I call runModalForWindow: in a class method initializer -- the class is a NSWindowController subclass-- from a controller of a sheet. Please, disregard UI Guidelines, it's a highly customized app and this approach used as per specific request.
+ (id)selectItem {KSingleItemSelectorController *newSelector = [[KSingleItemSelectorController alloc] initWithWindowNibName:@"SingleItemSelector"];
(void)[newSelector window]; NSLog(@"The window is nil, see: %@",[newSelector window]); [NSApp runModalForWindow:[newSelector window]]; id keepThis = newSelector.returnValue; [newSelector release]; return keepThis; } As a result I am getting the following message: 2009-01-13 14:10:49.424 Secret[76477:10b] loading 2009-01-13 14:10:49.425 Secret[76477:10b] The window is nil, see: (null)2009-01-13 14:10:49.438 Secret[76477:10b] *** Assertion failure in - [KApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo :], /SourceCache/AppKit/AppKit-949.35/AppKit.subproj/NSApplication.m: 3031 2009-01-13 14:10:49.439 Secret[76477:10b] Modal session requires modal window
I read up on the different threads across the forums on this message to no avail, so I tried something different because I found no way so that my subclass would actually ever get its window, regardless how I initialized it.
In turn now, when I do the following everything works: + (id)selectItem {KSingleItemSelectorController *newSelector = [[KSingleItemSelectorController alloc] initWithWindowNibName:@"SingleItemSelector"]; NSWindowController *ersatz = [[NSWindowController alloc] initWithWindowNibName:@"SingleItemSelector"];
[ersatz loadWindow]; [newSelector setWindow:[ersatz window]]; [ersatz release]; [NSApp runModalForWindow:[newSelector window]]; id keepThis = newSelector.returnValue; [newSelector release]; return keepThis; }This second option is unacceptable but just for experimenting to understand where the source of the problem is. It suggests to me that there is no reason for the first approach not to work, given I excluded all other possible faults, like wrong subclass, no delegate or subclass assignment of File's owner and so forth.
Finally I found a third way: + (id)selectItem {KSingleItemSelectorController *newSelector = [[self alloc] initWithWindowNibName:@"SingleItemSelector"];
[NSBundle loadNibNamed:[newSelector windowNibName] owner:newSelector]; [NSApp runModalForWindow:[newSelector window]]; id keepThis = newSelector.returnValue; [newSelector release]; return keepThis; }This works, too. The question is why the initial way doesn't work and the second one does, where either both or none of both should work. I read through the documentation on Resource Programming Guide, but in the end found so many answers,I wonder which of all three is the correct one, or is there a fourth and they are all wrong?
Alex
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com