[comp.sys.next] How to obtain object id's loaded with loadNibFile

jvkelley@watcgl.waterloo.edu (Jeff Kelley) (05/28/90)

How can an application determine what objects were loaded
using the Application class' loadNibFile method?

The nib files being loaded are created independently of the
application.  The application may wish to set
text fields, slider settings, etc. of the loaded objects
based upon decisions that can only be made at run time.

Thanks.  Excuse my ignorance if this is a stupid question,
I've only been playing with a NeXT for a week.

--
Jeff Kelley    National Research Council of Canada, Ottawa
   uunet!watmath!watcgl!jvkelley  	tel:   (613) 990-5924

jvkelley@watcgl.waterloo.edu (Jeff Kelley) (05/29/90)

In article <1990May27.193144.21730@watcgl.waterloo.edu> jvkelley@watcgl.waterloo.edu (Jeff Kelley) writes:
>How can an application determine what objects were loaded
>using the Application class' loadNibFile method?
>
>The nib files being loaded are created independently of the
>application.  The application may wish to set
>text fields, slider settings, etc. of the loaded objects
>based upon decisions that can only be made at run time.
>

Easy, stupid.  The id returned by the loadNibFile with be that
of the new panel.  Use the contentView method to get the panel's
view hierarchy, then use the findViewWithTag method to find the
controls in the view hierarchy.

Of course this requires that unique tags be assigned to the controls,
but for sliders, buttons, etc. you can do that with interface builder.
If you really want to strain your brain, explain how to set the tag
of a custom control (i.e. application created Control subclass)
using interface builder.  Is it possible?

--
Jeff Kelley    National Research Council of Canada, Ottawa
   uunet!watmath!watcgl!jvkelley  	tel:   (613) 990-5924

jacob@gore.com (Jacob Gore) (05/29/90)

/ comp.sys.next / jvkelley@watcgl.waterloo.edu (Jeff Kelley) / May 28, 1990 /
> In article <1990May27.193144.21730@watcgl.waterloo.edu>
> jvkelley@watcgl.waterloo.edu (Jeff Kelley) writes:
> >How can an application determine what objects were loaded
> >using the Application class' loadNibFile method?
> ...
> Easy, stupid.  The id returned by the loadNibFile with be that
> of the new panel.  Use the contentView method to get the panel's
> view hierarchy, then use the findViewWithTag method to find the
> controls in the view hierarchy.
> 
> Of course this requires that unique tags be assigned to the controls,
> but for sliders, buttons, etc. you can do that with interface builder.
> If you really want to strain your brain, explain how to set the tag
> of a custom control (i.e. application created Control subclass)
> using interface builder.  Is it possible?

Sorry to interrupt your string of self-abuse, but: couldn't you just assign
names to these controls, and then use NXGetNamedObject()?

Jacob
--
Jacob Gore		Jacob@Gore.Com			boulder!gore!jacob

jvkelley@watcgl.waterloo.edu (Jeff Kelley) (05/29/90)

In article <130072@gore.com> jacob@gore.com (Jacob Gore) writes:
>> In article <1990May27.193144.21730@watcgl.waterloo.edu>
>> jvkelley@watcgl.waterloo.edu (Jeff Kelley) writes:
>> >How can an application determine what objects were loaded
>> >using the Application class' loadNibFile method?
>> ...
>Sorry to interrupt your string of self-abuse, but: couldn't you just assign
>names to these controls, and then use NXGetNamedObject()?
>
>Jacob
>--
>Jacob Gore		Jacob@Gore.Com			boulder!gore!jacob

I tried using NXGetNamedObject but couldn't get it to work.  Specifically,
I did something like:

	manager = [PanelManager new]; /* PanelManager handles object messages */
	panel = [NXApp loadNibFile:filename owner:manager withNames:YES];
	slider = NXGetNamedObject( "Slider2"/*name*/, manager/*owner*/ );

where I assigned the name "Slider2" or somesuch to an object using IB.
The result in 'slider' was always nil.  I traced the code of NXGetNamedObject
and got the impression that it references the Applications _nameTable
instance variable, which I believe was a List.  I found that the number
of items in the _nameTable List didn't change after calling loadNibFile.
However, in 'main()' where the initial loadNibSection is performed, I
found the _nameTable made a transition from nil to a list of 30 objects
or so.  I was somewhat confused by this behaviour.

To sum up, the behaviour I would expect from loadNibFile: owner: withNames:YES
is that the loaded objects would then be accessible with NXGetNamedObject
using the owner specified to loadNibFile.  If someone can confirm that this
does indeed work (and point out what I'm doing wrong) I would use this approach.
(I still don't have any printed docs, just what's online).

--
Jeff Kelley    National Research Council of Canada, Ottawa
   uunet!watmath!watcgl!jvkelley  	tel:   (613) 990-5924