Wednesday 15 April 2015

objective c - Weird NSLog behaviour: NSLog displaying window controller's window -


I do not understand what's happening here. I have a wired button to do the following tasks in an AppDelegate:

  - (IBAction) openWindow: (ID) sender {self.winCon = [[NSWindowController alloc] initWithWindowNibName: @ "NewWindow" ]; } Clicking on the button does not happen (expected), but when I change the code (add  NSLog () )  
  - (IBAction) openWindow: (ID) sender {self.winCon = [[NSWindowController alloc] initWithWindowNibName: @ "NewWindow"]; NSLog (@ "% @", self.winCon.window); }   

A 'window' window comes up. Why does this happen In addition NSLog prints in the (null) console.

('Newwondo' is the NSObject of the file owner in xibb and i have not wired the window reference, so i was expecting the log to print null , but The second thing, when I use it:

  - (IBAction) openWindow: (ID) sender {[NSBundle loadNib nominated: @ "NewWondo" owner: self.winCon]; }   

On the click of a button, the window is displayed. Why does this happen Nib is not loading and the window is displaying different processes. I should not call showWindow: or makeKeyAndOrderFront: to display the window?

When I read a special piece of apple docks in:

Opening a window, which is showing a window, usually By putting the window into the application's window list, one can create a way that makes MacAye and orderfrants:, orderfrent:, etc., in the NSWWO, and so on. In addition, with some bits set in the interface builder, the window is shown when the Nib file is loaded in some cases.

I think that loadNib is nominated: .. to open the window but these 'bits are set in the interface builder' Where can I find it? (Apart from this, I can stop the window from opening in upper case when I can uncheck the window property 'Show on launch' - to give some further explanation about this property Will help.) Thanks. / P>

Note: I know how to initialize the nibb by using the NSBindowController subclass and have proper wiring in xib, but I'm only curious about the above behavior.

To answer your first question, when you enter NSLog (@ "% @" , Self.winCon.window) writes; You are actually sending a message to display the window in the window controller frequency wincon , and then it will output an additional description message to a string Is being sent to the console in the normal message syntax (not dot notation) and the format string is written using "% s", you are doing this: NSLog (@ "% s ", [[[Self WinCon] window] description) . Accordingly, the window will try to load the window window example and window if it has not already been displayed.

loadNib named: owner: The NSBundle method should be used only when you are not using the window controller. There are two different actions to load a nib file and display windows. If you have not done this already, then you should read the above file owner's placeholder and how xib files are stored in Nib files. It is being said, your show windward method should look like the following (although you should actually subclass NSWindowController and have already started it - I know that does not make sense): < Pre> - (IBAction) openWindow: (ID) sender {self.winCon = [[NSWindowController alloc] initWithWindowNibName: @ "NewWondo"]; [Self.winCon sh owWindow]; }

No comments:

Post a Comment