Re: NSView and NSMenuItem not updating displays
Re: NSView and NSMenuItem not updating displays
- Subject: Re: NSView and NSMenuItem not updating displays
- From: Matt Neuburg <email@hidden>
- Date: Sat, 05 Feb 2005 10:17:54 -0800
On Fri, 4 Feb 2005 16:15:31 -0500, Matt Wilks <email@hidden>
said:
>On Fri, Feb 04, 2005 at 08:25:07AM -0800, Matt Neuburg wrote:
>> On Thu, 3 Feb 2005 15:57:09 -0500, Matt Wilks <email@hidden>
>> said:
>> >I've got a custom NSView and a couple of NSMenuItems (in the main menu)
>> >declared like so:
>> >
>> > IBOutlet ConnectStatus *status = [[ConnectStatus alloc] init];
>> > IBOutlet NSMenuItem *connectItem = [[NSMenuItem alloc] init];
>> > IBOutlet NSMenuItem *disconnectItem = [[NSMenuItem alloc] init];
>>
>> If you are creating these objects yourself, then in what sense are these
>> IBOutlets?
>
>I define them in the AppController.h file:
>
> IBOutlet ConnectStatus *status;
>
>and then intialize them in the 'init' function of AppController.m as
>above
The fact that you are saying IBOutlet suggests to me that you think that
e.g. "status" is an ivar pointing at something in a nib. For example, when I
say in a .h file:
IBOutlet NSTableView* theTable;
...that is a sign to myself that I have drawn a connection in Interface
Builder between an instance of this class and an instance of a table view in
the nib. Now, on the other hand, if I say:
NSTableView* theTable = [[NSTableView alloc] initWithFrame: ....];
...that is a completely different behavior; "alloc" means that I am
*creating* a table view, ex nihilo, in code, and assigning it to this
variable.
It would not make sense to me to do *both*, because on startup of the app,
the table view in my nib would be assigned to "theTable", but then I would
immediately unassign it - and assign instead the instance of "theTable" that
I created in code. If I were then to speak to the variable "theTable", the
table view that would be affected would be the one I created in code. Since
that is not the one in my window in the nib, the one in my window in the nib
would not register any changes - *a* table view would be affected, but not
the one that I can *see*.
So that is why I am suggesting that combining the notion that this is an
IBOutlet with the notion that you create and assign the value of the ivar in
code is a very strange thing to do. There might be a reason for doing it,
and I have done things like this, but your reply does not fill me with
confidence that you have such a reason - in fact, your response makes it
seem more likely to me that you are simply saying some words (alloc/init)
without the slightest understanding of what you are doing. Like the
Sorcerer's Apprentice, you have said the magic spell that has caused you to
have *two* "status" objects, without desiring or realizing this.
Now let's return to your original complaint that you were worried about
initializing your NSView. The problem might be that you don't understand how
objects in a nib get initialized. It might also be that you don't understand
what a designated initializer is (because "init" is not the proper
initializer for an NSView under any circumstances). So let me suggest that
perhaps you should RTFM on initialization of things. In particular, read the
docs on NSView, where you are told what the designated intializer is, but
also read the Interface Builder FAQ (under the Help menu) in "Why isn't my
initWithFrame: method called?" (and the following stuff on initWithCoder: as
well).
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden