hackiftekhar / IQDropDownTextField

TextField with DropDown support using UIPickerView
MIT License
309 stars 87 forks source link

Impossible to make an action when value change #49

Closed OxyFlax closed 8 years ago

OxyFlax commented 8 years ago

I would like to call a method when the value is change (in order to enable a button when something is selected in pickerView) but nothing seems to work, do you have any idea? I tried this: [_TextFieldPicker addTarget:self action:@selector(checkFields) forControlEvents:UIControlEventValueChanged];

hackiftekhar commented 8 years ago

There Is a delegate method for this something like didSelectItem. This will do the trick for you.

OxyFlax commented 8 years ago

What do you mean? When you select a value, I need to call the function checkFields that is this one: -(void)checkFields { self.createButton.enabled = self.pseudoTextField.text.length > 0 && self.passwordTextField.text.length > 0 && self.confirmPasswordTextField.text.length > 0 && _questionTextFieldPicker.selectedRow != -1 && _questionAnswerTextField.text.length > 0 && _cityTextField.text.length > 0 && _addressTextView.text.length > 0; } Sorry, I'm new in Objective-C so I don't know where to put didSelectItem

hackiftekhar commented 8 years ago

Ok, then you could learn about delegate first. There are delegate methods to get a callback like you want.

OxyFlax commented 8 years ago

Ok thanks, I tried that: `-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

// my action

}` But it doesn't work. Is that what you were talking about?

hackiftekhar commented 8 years ago

That's the delegate of UIPickerView. You should use IQDropDownTextField delegates.

OxyFlax commented 8 years ago

Ok sorry, I didn't look at the .h file. I tried that: -(void)textField:(nonnull IQDropDownTextField*)textField didSelectItem:(nullable NSString*)item { [self checkFields]; NSLog(@"Problem is from elsewhere"); } But it doesn't work either.

hackiftekhar commented 8 years ago

You didn't set textField.delegate property to self that's why you didn't get a callback.

OxyFlax commented 8 years ago

Thank you very much, it worked. And you helped me for my future development I think, as I now know better how to use delegate :)