键盘没有在cocos2d中显示uitextfield

时间:2011-12-24 11:24:19

标签: iphone cocos2d-iphone

以下是要显示的代码。

UIViewController* viewControoler = [[UIViewController alloc]init];
textfield = [[UITextField alloc]initWithFrame:CGRectMake(0,0,280,90)]; 
textfield.placeholder = @"word";
textfield.keyboardType = UIKeyboardTypeDefault;
textfield.returnKeyType = UIReturnKeySearch;
textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
textfield.delegate = self;
textfield.userInteractionEnabled = YES;
[textfield becomeFirstResponder];
[viewControoler.view addSubview:textfield];
[[[CCDirector sharedDirector]openGLView] addSubview:viewControoler.view];

运行良好。但是文本字段不可编辑,因为当我点击uitextfiled时,键盘不会出现。

1 个答案:

答案 0 :(得分:1)

删除UIViewController,直接添加OpenGLView,

textfield = [[UITextField alloc]initWithFrame:CGRectMake(0,0,280,90)]; 
textfield.placeholder = @"word";
textfield.keyboardType = UIKeyboardTypeDefault;
textfield.returnKeyType = UIReturnKeySearch;
textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
textfield.delegate = self;
textfield.userInteractionEnabled = YES;
[textfield becomeFirstResponder];

[[[CCDirector sharedDirector]openGLView] addSubview:textfield;