FROM : Andy Lee
DATE : Mon Apr 28 23:53:09 2008
Yup, that's right.
An object that has a delegate sends certain pre-defined messages to
the delegate at certain times. Those times are described by the name
of the delegate method. For example, "controlTextDidChange:" is sent
after the text in an NSControl changes. The naming convention is very
consistent throughout Cocoa. Delegate methods sound almost like
newspaper headlines: "window will close", "file manager should proceed
after error", etc.
You can see the list of delegate methods an object supports by looking
at its class documentation. You wouldn't have found -
controlTextDidChange: by looking at NSTextField, but by going up the
inheritance hierarchy you would have found NSControl's delegate methods.
The delegate contract is quite relaxed. If the object's delegate is
nil, it doesn't send any delegate messages. If the delegate doesn't
implement all the delegate methods, only the messages that are
implemented are sent. The delegate can be an instance of any class --
all that matters is what methods it implements. So you can implement
only what you need.
--Andy
On Apr 28, 2008, at 5:06 PM, Philip Bridson wrote:
> Ok. Thanks for the reply - this may sound stupid but I haven't dealt
> with delegates much. If I make the window controller the delegate
> would I just declare a method in that window controller's files as
> below?
>
> - (void)controlTextDidChange:(NSNotification)notification
> {
> runMyFunction();
> }
>
> Sorry if I seem stupid but as I say I don't use them much.
>
> Thanks,
>
> Phil
>
> On Monday, April 28, 2008, at 08:34PM, "Andy Lee" <<email_removed>>
> wrote:
>> Give your text field a delegate, and in the delegate implement -
>> controlTextDidChange:.
>>
>> See the docs for more details.
>>
>> --Andy
>>
>> On Apr 28, 2008, at 3:17 PM, Philip Bridson wrote:
>>
>>> Hi there,
>>>
>>> I want to create a password analysis tool that updates an
>>> NSLevelIndicator with each character entered into a
>>> NSSecureTextField. I know how to update the NSLevelIndicator once
>>> the
>>> user has finished entering text but how do i update it per
>>> character?
>>>
>>> To give you a bit more info:
>>>
>>> The text is passed to a function: the function returns a value: the
>>> value is used to update the level indicator.
>>>
>>> This works fine but I can only do it once the whole word is in the
>>> field. How do I pass characters as they are entered to my func? Such
>>> as:
>>>
>>> 1. P
>>> 2. Pa
>>> 3. Pas
>>> 4. Pass
>>> 5. Passw
>>> 6. Passwo
>>> 7. Passwor
>>> 8. Password
>>>
>>> Thank you for any help you might give.
>>>
>>> Phil.
>>>>
>>>>
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (<email_removed>)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>>
>>> This email sent to <email_removed>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (<email_removed>)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>
>> This email sent to <email_removed>
>>
>>
DATE : Mon Apr 28 23:53:09 2008
Yup, that's right.
An object that has a delegate sends certain pre-defined messages to
the delegate at certain times. Those times are described by the name
of the delegate method. For example, "controlTextDidChange:" is sent
after the text in an NSControl changes. The naming convention is very
consistent throughout Cocoa. Delegate methods sound almost like
newspaper headlines: "window will close", "file manager should proceed
after error", etc.
You can see the list of delegate methods an object supports by looking
at its class documentation. You wouldn't have found -
controlTextDidChange: by looking at NSTextField, but by going up the
inheritance hierarchy you would have found NSControl's delegate methods.
The delegate contract is quite relaxed. If the object's delegate is
nil, it doesn't send any delegate messages. If the delegate doesn't
implement all the delegate methods, only the messages that are
implemented are sent. The delegate can be an instance of any class --
all that matters is what methods it implements. So you can implement
only what you need.
--Andy
On Apr 28, 2008, at 5:06 PM, Philip Bridson wrote:
> Ok. Thanks for the reply - this may sound stupid but I haven't dealt
> with delegates much. If I make the window controller the delegate
> would I just declare a method in that window controller's files as
> below?
>
> - (void)controlTextDidChange:(NSNotification)notification
> {
> runMyFunction();
> }
>
> Sorry if I seem stupid but as I say I don't use them much.
>
> Thanks,
>
> Phil
>
> On Monday, April 28, 2008, at 08:34PM, "Andy Lee" <<email_removed>>
> wrote:
>> Give your text field a delegate, and in the delegate implement -
>> controlTextDidChange:.
>>
>> See the docs for more details.
>>
>> --Andy
>>
>> On Apr 28, 2008, at 3:17 PM, Philip Bridson wrote:
>>
>>> Hi there,
>>>
>>> I want to create a password analysis tool that updates an
>>> NSLevelIndicator with each character entered into a
>>> NSSecureTextField. I know how to update the NSLevelIndicator once
>>> the
>>> user has finished entering text but how do i update it per
>>> character?
>>>
>>> To give you a bit more info:
>>>
>>> The text is passed to a function: the function returns a value: the
>>> value is used to update the level indicator.
>>>
>>> This works fine but I can only do it once the whole word is in the
>>> field. How do I pass characters as they are entered to my func? Such
>>> as:
>>>
>>> 1. P
>>> 2. Pa
>>> 3. Pas
>>> 4. Pass
>>> 5. Passw
>>> 6. Passwo
>>> 7. Passwor
>>> 8. Password
>>>
>>> Thank you for any help you might give.
>>>
>>> Phil.
>>>>
>>>>
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (<email_removed>)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>>
>>> This email sent to <email_removed>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (<email_removed>)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>
>> This email sent to <email_removed>
>>
>>
| Related mails | Author | Date |
|---|---|---|
| Philip Bridson | Apr 28, 21:17 | |
| Michael Vannorsdel | Apr 28, 21:26 | |
| Andy Lee | Apr 28, 21:32 | |
| Philip Bridson | Apr 28, 23:06 | |
| Andy Lee | Apr 28, 23:53 |






Cocoa mail archive

