以下是要显示的代码。
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时,键盘不会出现。
答案 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;