Chapter 12 : TextField Delegate

I do not understand why :
The textField need a delegate, but the doneButton, cancelButton… do not need delegate ???

To explain that, it might be necessary to ask you what do you understand as the functionality of the delegate? Why do you think a delegate is used in code?

Q1 : i do not understand what is functionality of delegate.
Q2 : if i do not use delegate the done can not change its state, although i wrote code in addItem Class.

First, you might want to take a look at Chapter 9 - page 209 to read briefly about what a delegate is. If that doesn’t give you enough information, then take a look at Chapter 13 which covers delegates in detail. After that, if you still don’t understand what a delegate does, then let me know and I’ll try to point you in the direction of additional references.

Without understanding the concept of a delegate, explaining the rest to you would not make much sense. Once you understand the concept of a delegate, I believe you would know the answer to your original question yourself :slight_smile:

i think i have a fuzzy concept about delegate.
I have another question :
Why do not use @IBAction for textfield like < done || cancel> button???
I think change text in textfield also a action.
Why need a delegate instead of a @IBAction???

After read about UITextField, i think when i need do a task, i need a delegate.
But i can not distinguish between action and task?
Does action mean TAP or click???

Whether it is an IBAction or a delegate method, essentially it is the same thing - a method which does something in your code. The reason you have two different items is based on the type of control and how each control was designed.

For example, buttons have target actions for specific actions since that was how the control was designed. If a button was designed to follow the delegate pattern instead, then you’d be setting delegates for buttons too.

In the case of text fields, they are designed to work via a delegate. And if you look at the UITextField class reference, you’ll notice that it has a delegate property. This is usually an indicator that a class of that type adheres to the delegate pattern.

I think of it as follows: If the thing to be done is simple, it is generally an @IBAction - Buttons, checkboxes etc. tend to have actions - essentially a link to a single function. But when there are large numbers of things that need code, the thing that does that is called a delegate. It is an object that can respond to multiple messages so it has multiple methods (UITextFieldDelegate has seven different ones defined). So it really boils down to the complexity of the behavior required for a given control.

Thank for help! scarrg…
your explanation is simple to understand

This topic was automatically closed after 166 days. New replies are no longer allowed.