Re: Please help a newbie with delegation!
Re: Please help a newbie with delegation!
- Subject: Re: Please help a newbie with delegation!
- From: Adam Wainwright <email@hidden>
- Date: Fri, 25 Feb 2005 21:02:51 +0000
Many thanks for the responses and the info!
Thanks for the description of the initialisation of a cocoa process and the pointers to the proper answer, they were most enlightening.
I now sort of realise where I was going wrong.
I implemented
<x-tad-bigger>- (BOOL)control:(NSControl *)</x-tad-bigger>control<x-tad-bigger> textShouldEndEditing:(</x-tad-bigger><x-tad-bigger>NSText</x-tad-bigger><x-tad-bigger> *)</x-tad-bigger>fieldEditor
and delegated via the IB interface. My code is now called.
I am still a bit wet behind the ears I'm afraid - I took a look at the delegate functions for NSTextField assuming they were the delegate functions I needed, whereas the NSControl's delegate functions are what I needed.
Back to coding!
Best wishes
Adam
--
Does dim atal y llanw!
On 25 Feb 2005, at 20:35, Harilaos Skiadas wrote:
The objects are nil, and any message sent to a nil
object is discarded.
IBOutlets aren't connected at init time; they're
connected when the nib
is instantiated. If your class implements the method
-awakeFromNib,
then that method will be called when the
instantiation process is done.
To elaborate a bit more, the order of events, as far
as I understand it, is:
1) The controller is inited.
2) The controller inits the window, using the
information from the NIB file.
3) All objects in the window are inited, and
connections are drawn. (outlets etc)
4) The controller's awakeFromNib method is called.
There are probably other things that I am missing
here, but these are the relevant bits.
So when the controller is inited, it created the two
variables (outlets) textField1 and textField2, but at
that point it has nowhere to connect them to, so they
are set to nil.
Once the window is loaded, the controller sees what
variables it has and connects them to the appropriate
elements of the window. Now, i.e. after step 3, the
outlets in your code are connected to the text fields
that reside in the window.
So in the awakeFromNib method you can do what you
want, having established the necessary links.
Everybody, please correct me if I am wrong.
What I don't understand though, is why you have not
set your controller (i.e. File's Owner) as the
delegate of the text fields in interface builder,
instead of trying to do it programmatically (other
than to learn about awakeFromNib and other wonderful
stuff of course :-) )? Also, is it an application
controller, or just a window controller?
Also, text fields use a different set of delegate
methods than the ones
you're trying to use; look at the documentation for
NSControl to see
the methods you should implement.
Nick Zitzmann
<http://www.chronosnet.com/>
Haris
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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