UITextfield with multiple delegates

I am using JJMaterialTextField custom UITextField class. It has some delegates for animation placeholder etc..I want to use some other delegates too for UIViewController which uses that class. If I write down delegate.self for JJMaterialTextField class object in UIViewController, I does not perform its own delegates, it perform only delegates methods in UIViewController. But I want to that it should perform both delegate methods. How can I do it? Thanks.

Upvotes: 1

Views: 856

Answers (2)

Bhumit Muchhadia
Bhumit Muchhadia

Reputation: 128

Done use delegates in the view control, instead use this

[textField addTarget:self 
              action:@selector(textFieldDidChange:) 
    forControlEvents:UIControlEventEditingChanged];

It will behave like delegate it will fire when text changes, there are also other selectors textFieldDidBegin.. etc. This way you wont interrupt the delegates.

Upvotes: 5

Ladislav
Ladislav

Reputation: 7283

It is mostly considered a bad idea if you need multiple delegates. Delegates are all about 1-1 relationship.

Please read the answer here, it will give you pointers on how you could proceed with observers or with notifications

Multiple Delegates in iOS

If you don't want to go with the recommendations above take a look at first and second answer on how you can do it, basically create a object that holds references to multiple delegates, then you can just look over them and post delegate methods that way:

Delegation to multiple objects

Upvotes: 0

Related Questions