UITextField textFieldDidBeginEditing: Not called on the first selection
I'm trying to set up an action that happens immediately when a UITextField starts editing (changing some text to help the user with what to put in the field in an external view that slides in)
I've included the UITextFieldDelegate in my View Controller, and implemented the textFieldDidBeginEditing: method, however this method seems to only be called after the first time the UITextField is selected (it doesn't get called the first time).
Is there any reason this is happening which can be prevented, or is there a better way to do this? (ie check which text field is editing when the UIButton is pressed).
The help panel (helpPanel) is loaded in the viewDidLoad: method.
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == tfMyTextField) {
[helpPanel setTextTitle:@"'Title'"];
[helpPanel setText:@"'message'"];
}
}
-(IBAction)showHelp:(id)sender {
[self dismissAllInputs];
SidePanelController *side = (SidePanelController *)[[UIApplication sharedApplication] delegate].window.rootViewController;
[side showLeftPanelAnimated:YES]; // the left panel is the helpPanel instance
}
It sounds like a simple matter of the order in which things happen. Consider this code:
if (textField == tfMyTextField) {
[helpPanel setTextTitle:@"'Title'"];
[helpPanel setText:@"'message'"];
}
You are assuming that helpPanel
already exists and can be updated. But if it hasn't appeared yet, perhaps it doesn't exist yet.
So instead, try this: do not set the helpPanel
title and text until after you call [side showLeftPanelAnimated:YES]
.