I\'ve searched through this site that I couldn\'t find a solution to the problem I\'m facing now. Hope someone can help.
I\'ve created a UIAlertView to prompt user
What happens if you move the releasing of the text field to the delegate method, after you call the resignFirstResponder method?
simply do
[mytextField addTarget:self
action:@selector(methodToFire:)
forControlEvents:UIControlEventEditingDidEndOnExit];
if anyone is having trouble with this in storyboard i had to go into my uitextfields properties and ctrl+drag from its delegate to its root view controller all in storyboard and that fixed everything..
First you need to define your enterNameAlert
in interface header. then use the below code.
- (void)viewDidLoad {
[super viewDidLoad];
enterNameAlert = [[UIAlertView alloc] initWithTitle:@"Enter your name"
message:@"\n\n\n"
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
otherButtonTitles:NSLocalizedString(@"OK", nil),nil];
UITextField *enterNameField = [[UITextField alloc] initWithFrame:CGRectMake(16, 83, 252, 25)];
enterNameField.keyboardAppearance = UIKeyboardAppearanceAlert;
enterNameField.borderStyle = UITextBorderStyleRoundedRect;
enterNameField.autocorrectionType = UITextAutocorrectionTypeNo;
enterNameField.clearButtonMode = UITextFieldViewModeWhileEditing;
enterNameField.returnKeyType = UIReturnKeyDone;
enterNameField.delegate = self;
[enterNameAlert addSubview:enterNameField];
[enterNameField becomeFirstResponder];
[enterNameAlert show];
[enterNameField release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
[enterNameAlert dismissWithClickedButtonIndex:1 animated:YES];
[enterNameAlert release];
NSLog(@"text field was first responder");
} else {
[textField becomeFirstResponder];
[textField resignFirstResponder];
NSLog(@"text field was not first responder");
}
NSLog(@"textfieldshouldreturn");
return YES;
}
Have another object become and then immediately resign the first responder.
Try dismissing keyboard using resignFirstResponder on "DidEndOnExit" event of your TextField.
Then try to dismiss keyboard by pressing Done button on keyboard when you have finished entering the data into your TextField.
Hope this helps.