Re: Just starting out..... Please help
Re: Just starting out..... Please help
- Subject: Re: Just starting out..... Please help
- From: Chris Gehlker <email@hidden>
- Date: Sun, 08 Jul 2001 22:22:35 -0700
On 7/8/01 9:29 PM, "Graham Wihlidal" <email@hidden> wrote:
>
Hey list,
>
>
I have some questions I was hoping you could answer. I already
>
understand how outlets, actions, etc.. work
>
>
But, how do I call a function defined in an Obj-C class that is made
>
for an event from InterfaceBuilder to call it normally?
>
>
Eg)
>
>
- (void)LoginWindow_Display:(id)sender
>
{
>
[LoginWindow center];
>
[LoginWindow makeKeyAndOrderFront:self];
>
}
>
>
I have that code attached to a button in my interface. It works fine..
>
How can I call that in code regardless of the interface?
>
>
- (void)LoginWindow_Display:(id)sender
>
{
>
[LoginWindow center];
>
[LoginWindow makeKeyAndOrderFront:self];
>
}
These aren't function calls. They are messages and you have to send them to
some actual object that can receive them. Something like:
[myLoginWindow LoginWindow_Display: self];
This means you have to instantiate a LogWindow instance to be a receiver of
the message first with:
LoginWindow *myLoginWindow = [[LoginWindow alloc] init];
So there will be something to receive the message.
Or
Put a visible log in widow and an invisible main window in the nib. Either
way, there has to be an instance of the login window before you can send it
messages.
>
I tried this:
>
>
[nil AboutWindow_Display];
>
>
It compiled but didn't work. Anyone know how?
It did work. It sent an AboutWindow_Display message to nil. Of course
nothing happened as a result of that because nil won't respond to any
messages.
I'm really not trying to be flip. It's just obvious that you don't "get" OOP
yet. Messages are not function calls. For what I'm guessing you are trying
to do, just make a message window with an NSTextFeld. Have the NSTextField
in the window send a message to your controller object when the user hits
enter or return. Then the controller can send a message to the NSTextField
asking for the text that was entered and see if it's a valid password. If it
is, your controller can send a message to you main window telling it to
become visible.
--
C++: The power, elegance and simplicity of a hand grenade.