programmatically placing GUIs
-
I am trying to place and size segmented controls programmatically on
a window controlled by a subclass of NSWindowController. What I'm
getting, however, is simply the window as it was initially drawn in
IB. I think the problem has to do with loading the window properly
and more specifically, getting the segmented control variables to
know which window they are being redrawn in.
I declared an outlet "window" to match the nib outlet (window), and
also physically drew in dummy controls on within IB. When I try to
actually ruun the program and init the window controller using
initWithNibName:, I notice that "window" has no memory associated it.
Since I want to size my controls programmatically, this seems to be a
problem, since their "_window" variable is naturally also null as a
result. The controls are initially drawn in IB but are suppose to
resize during -windowWillLoad.
In addition, I see that in the debugger there is both a "window" and
a "_window" variable under self (the controller). Does this mean you
are not supposed to formally declare an outlet for the controller's
window?
Bottom line, I am getting a window that looks like what I drew in IB,
not the one modified programmatically.
I feel I am going about this the wrong way but don't see any
documentation on this particular issue. If anyone could shed some
light on the procedure, it would be a big help. Thanks.
Daniel -
On Feb 27, 2008, at 2:25 PM, Daniel Child wrote:> I am trying to place and size segmented controls programmatically on
> a window controlled by a subclass of NSWindowController. What I'm
> getting, however, is simply the window as it was initially drawn in
> IB. I think the problem has to do with loading the window properly
> and more specifically, getting the segmented control variables to
> know which window they are being redrawn in.
>
> I declared an outlet "window" to match the nib outlet (window), and
> also physically drew in dummy controls on within IB. When I try to
> actually ruun the program and init the window controller using
> initWithNibName:, I notice that "window" has no memory associated
> it. Since I want to size my controls programmatically, this seems to
> be a problem, since their "_window" variable is naturally also null
> as a result. The controls are initially drawn in IB but are suppose
> to resize during -windowWillLoad.
>
> In addition, I see that in the debugger there is both a "window" and
> a "_window" variable under self (the controller). Does this mean you
> are not supposed to formally declare an outlet for the controller's
> window?
>
> Bottom line, I am getting a window that looks like what I drew in
> IB, not the one modified programmatically.
>
> I feel I am going about this the wrong way but don't see any
> documentation on this particular issue. If anyone could shed some
> light on the procedure, it would be a big help. Thanks.
>
I'm going through some of the same stuff and it's not easy. It's hard
for me to tell how far along you are, but some of Apple's sample code
has helped me with programmatic creation of controls and their
placement in the window. ButtonMadness in particular uses placeholders
for some controls in the window nib and replaces them with
programmatically created controls at runtime.
Ken
--
Ken Worley
Software Engineer, Tiberius, Inc. -
On Feb 27, 2008, at 15:21, Daniel Child wrote:> In IB, targets / outlets are set as normal. The window delegate is
> set to File's Owner (the window controller) so that I can call -
> windowWillLoad to resize all the GUIs prior to loading. Is there
> anything else I could be missing?
>
'windowWillLoad' isn't something you call, it's something you
override, and the window's delegate isn't involved with this. IAC it
seems like you would want to override 'windowDidLoad'. By definition,
the window doesn't exist before it's loaded from the nib. -
On Feb 27, 2008, at 3:25 PM, Daniel Child wrote:> In addition, I see that in the debugger there is both a "window" and
> a "_window" variable under self (the controller). Does this mean you
> are not supposed to formally declare an outlet for the controller's
> window?
NSWindowController has a window outlet already. Your custom subclass
of NSWindowController should not declare its own outlet.
The fact that NSWindowController uses "_window" as its ivar name
doesn't matter. The NIB-loading machinery will use setWindow: to
connect the outlet, not direct access to the ivar.
-Ken


