When I resign the first responder (UITextField-*nameField) via a background tap method, it is not calling the delegate Method. I am using UIKit with cocos2d. Any help is appreciated. Thank you!
Here is the code with the init Method:
CGRect frame = CGRectMake(115, 423,200, 32);
nameField = [[UITextField alloc] initWithFrame:frame];
nameField.borderStyle = UITextBorderStyleNone;
nameField.textColor = [UIColor blackColor];
nameField.textAlignment = UITextAlignmentLeft;
n开发者_开发百科ameField.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:24];
nameField.placeholder = @"Name";
nameField.backgroundColor = [UIColor clearColor];
nameField.autocorrectionType = UITextAutocorrectionTypeNo;
nameField.delegate = self;
nameField.keyboardType = UIKeyboardTypeDefault;
nameField.returnKeyType = UIReturnKeyDone;
[nameField isFirstResponder];
nameField.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameField];
And here is the Delegate Method I am calling. I am also conforming to the delegate protocol within the header file.
-(void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@"Name has been saved in NSUserDefauts");
NSUserDefaults *usrDef = [NSUserDefaults standardUserDefaults];
NSString *name = [[NSString alloc]initWithFormat:@"%@",nameField.text];
NSLog(@"%@",nameField.text);
[usrDef setObject:name forKey:@"Name"];
}
I think you have the wrong delegate method. The one I think you want is this:
- (void)textFieldDidEndEditing:(UITextField *)textField
精彩评论