UITextField委托方法和Cocos2d?

时间:2011-10-05 21:21:25

标签: objective-c cocoa-touch delegates cocos2d-iphone uitextfield

当我通过后台点按方法退出第一个响应者(UITextField- * nameField)时,它没有调用委托方法。我正在使用UIKit和cocos2d。任何帮助表示赞赏。谢谢!

以下是使用init方法的代码:

CGRect frame = CGRectMake(115, 423,200, 32);
nameField = [[UITextField alloc] initWithFrame:frame];
nameField.borderStyle = UITextBorderStyleNone;
nameField.textColor = [UIColor blackColor];
nameField.textAlignment = UITextAlignmentLeft;
nameField.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];  

这是我正在调用的委托方法。我也符合头文件中的委托协议。

-(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"];
}

1 个答案:

答案 0 :(得分:1)

我认为你有错误的委托方法。我认为你想要的是:

- (void)textFieldDidEndEditing:(UITextField *)textField