Editing Changed IB event fires before text is changed in a UITextField
I am firing the updateFindName
method by linking it to the Editin开发者_运维问答g Changed
event in IB. The problem is that the method seems to fire before recording the actual change in the UITextField
uiFindName
. I wanted to update the uiFindNameLabel
's text to uiFindName
's placeholder text when the user clears all text in uiFindName
, and it does, but only AFTER another character is typed into the uiFindName
. Any tips?
- (IBAction)updateFindName:(id)sender {
if ([uiFindNameLabel.text isNotEmpty]) {
uiFindNameLabel.text = uiFindName.text;
} else {
uiFindNameLabel.text = uiFindName.placeholder;
}
}
Note, isNotEmpty
is just a method checking for empty strings.
You could use the UITextField
's delegate method – textField:shouldChangeCharactersInRange:replacementString:
.
There you can determine exactly what the text before and after the entered character should be.
精彩评论