I have some textfields and I want to do when I change textfield1 text set text to other textfields. My code below. But it not works. How can I solve this?
- (IBAction)TCKimlikTextChange:(id)sender {
[TCKimlikText addTarget:self action:@selector(yourMethod: ) forControlEvents:UIControlEventEditingChanged];
}
-(void)yourMethod: (UITextField*)tf_{
if (tf_) {
if (TCKimlikText.text == @"1") {
AdinizText.text = @"Hacer";
}
}
}
Your code is very abstract.
yourMethod,tf_TCKimlikTextChangeare all expressions that are not very human readable. You should work on your variable names.I suppose your first method is a button handler. It just assigned a target and action to the text field, but does not call any method. You do not need that action if you use the delegate protocol.
To solve your problem: implement the
UITextFielddelegate methods. Make sure you set the delegate (probablyself) for your text fields. Your view controller must mention the<UITextFieldDelegate>protocol in its.hfile. Thus, intextField:shouldChangeCharactersInRange:replacementString::Notice that you need
isEqualToString:to compare strings, a simple==won’t do.