Thank you very much Andy and Jim I followed your remarks , played with the code and I am still surprised. It turns out that awakeFromNib is called before applicationDidFinishLaunching so there MyController is already initialized and has the correct window as the his instance variable. NSWindow has both a delegate protocol and a Controller class and so I called setDelegate and setController . Everything seems OK but the methods willLoad and didLoad are not called although clearly my class is both the delegate and the controller of my window . So I am still left asking what am I doing wrong (??).
Are there MacRuby code samples I can use. I read Lim,Chueng and McAnally book. I wonder where can I find more samples. I am also not sure I am doing everything correct with the IB . My blue box that represents MyController list "showWindow: " as a "Received Action" , but I could not connect it to any element of window draw in the XIB file. David class AppDelegate attr_accessor :window def applicationDidFinishLaunching(a_notification) puts " Insert code here to initialize your application" wCtrl = @window.delegate puts "no delegate" if wCtrl == nil win = wCtrl.window puts "win is nil" if win == nil puts "title of window is #{win.title}" ctrl = @window.windowController puts "no controller" if ctrl == nil puts "class of delegate is #{wCtrl.class}" puts "class of controller is #{ctrl.class}" puts "both are equal " if wCtrl == ctrl x = ctrl.showWindow puts "x class is #{x.class} " unless x == nil #puts "window nil " if win == nil #wCtrl.close end end class MyController < NSWindowController attr_accessor :window def initialize puts "in initialize" initWithWindowNibName("tow") #puts "after initialization window is #{@window.title}" end def routine puts "in routine" end #def initWithWindow(window) # puts "in initWithWindow" # super(@window) #end def awakeFromNib @window.setDelegate(self) @window.setWindowController(self) puts " at end of awake from nib. title is #{@window.title}" end def windowWillLoad puts "window will be soon loaded" end def windowDidLoad puts "window loaded" end def windowTitleForDocumentDisplayName(displayName) "Hello World" end def showWindow puts "in showWindow" super(self) end def close puts "in close window is #{@window.title}" super end end at end of awake from nib. title is two Insert code here to initialize your application title of window is two class of delegate is MyController class of controller is MyController both are equal in showWindow x class is MyController On Dec 1, 2012, at 3:00 AM, Andy Park wrote: > Without being able to verify anything for accuracy at the moment, it looks > like your window's delegate is not set to the controller at the time the > events are occurring. > > Check if you need to set this - try tracing the window's delegate at > different points of the controller's lifecycle. > > On 30 Nov 2012, at 00:50, david kramf <dakr....@gmail.com> wrote: > >> >> Hi, >> In the copied below code only the awakeFromNib is executed . Can someone >> explain me what do I do wrong ? Window is displayed and I expected all >> other methods to be called. >> Thanks, David >> >> >> class MyController < NSWindowController >> attr_accessor :window >> >> def awakeFromNib >> @window.delegate = self >> puts " at end of awake from nib. title is #{@window.title}" >> end >> >> def windowWillLoad >> puts "window will be soon loaded" >> end >> >> def windowDidLoad >> puts "window loaded" >> end >> def windowTitleForDocumentDisplayName(displayName) >> "Hello World" >> end >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo/macruby-devel > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel