You're creating two ViewController
instances, one with new
and one with alloc.initWithFrame()
.
new
is a class method that directly maps to alloc.init
, thus the @view
instance is calling .init
but the .alloc.initWithFrame()
is not.
The one that is outputting runEvent
's contents is the @view
instance (when it's created) and the one that's outputting the blank line is @cView
's instance (mouseDown
).
You need to set the variable in a common method and then provide an initWithFrame
method:
def initWithFrame(frame)
super
setVar
self
end
def init
super
setVar
loadWindow
self
end
def setVar
@var = "method called from event"
end
Works:
method called from event
(main)> method called from event
mouse click
(main)> method called from event
mouse click
Two asides: Always call super
in an init method you're overriding, and always return self
. Also, the way you're loading these ViewController
classes is kind of weird; it seems like you could move half the code into the AppDelegate
and avoid this ambiguity altogether.