I'm writing a document-based app in Swift, with a custom view controller class, 
and thus had to implement my own version of makeWindowControllers. However, for 
some reason the call to self.addWindowControllers does nothing at all. I tried 
stepping into it in the debugger, but that just stepped over the line.

I'm not sure if the bug is in my code or Apple's - I haven't seen any other 
users having this problem so I assume it is me.     

My document class contains the following (relevant) code:

var additionalWindowController: NSWindowController!             /* C */

override func makeWindowControllers() {
 let wc = MessageReadingViewController(windowNibName: 
"MessageReadingViewController")
 wc.document = self
 NSLog("have %d windowControllers", self.windowControllers.count)      /* A */
 self.addWindowController(wc)
 NSLog("have %d windowControllers", self.windowControllers.count)      /* A */
 self.additionalWindowController = wc                          /* C */
 wc.showWindow(self)                               /* B */
}

Lines A both print "have 0 windowControllers".

My MessageReadingViewController and associated nib seem to be valid - with 
lines B and C there the window is shown and (as far as my limited 
implementation of the UI can demonstrate) interacts correctly with the document 
object.

Without the lines marked C, the window controller, which isn't added to the 
windowControllers array, is released when the function ends and is thus 
immediately deallocated, closing the window almost instantly.

I haven't tried adding the window controller manually to the windowControllers 
array, mainly becuase I haven't found how to access a superclass's ivars 
directly in Swift.



For those not familiar with Swift, the above code approximately translated into 
Objective-C would be:

 @property NSWindowController *additionalWindowController; /* C */

-(void)makeWindowControllers{
 MessageReadingViewController *wc = [[MessageReadingViewController alloc] 
initWithWindowNibName: @"MessageReadingViewController"];
 [wc setDocument:self];
 NSLog("have %d windowControllers", self.windowControllers.count);     /* A */
 [self addWindowController: wc];
 NSLog("have %d windowControllers", self.windowControllers.count);     /* A */
 self.additionalWindowController = wc;                         /* C */
 [wc showWindow:self];                                         /* B */
}

(I'll crosspost this to the newsgroups comp.sys.mac.programmer.help and 
comp.lang.objective-c, and summarise the answers I get in each place to the 
other.)

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to