john doe
john doe

Reputation: 9660

Why do I get an error when I assign a UITextField Delegate to itself?

I am doing the following:

 self.firstNameTextField.delegate = self.firstNameTextField;

My firstNameTextField is a custom text field. I want the custom text field to handle all the delegate events. When I do the above I get the following warning:

Assigning to id from incompatible type UITextField.

What is this warning about and how can I remove it?

Upvotes: 2

Views: 1520

Answers (2)

rmaddy
rmaddy

Reputation: 318824

Your custom UITextField class needs to indicate that it conforms to the UITextFieldDelegate protocol.

@interface MyCustomTextField : UITextField <UITextFieldDelegate>

Also make sure that your firstNameTextField property is declared as:

@property (nonatomic) MyCustomTextField *firstNameTextField;

Upvotes: 5

Selkie
Selkie

Reputation: 1783

I think the problem is, the custom class is not conformed with UITextFieldDelegate protocol.

You should add it to your declaration like this

@interface MyController : NSObject <UITextFieldDelegate> 

Upvotes: 2

Related Questions