UITextField不接受IOS6的键盘输入

时间:2012-10-16 13:45:21

标签: iphone ios ipad uitextfield

我已将其缩小到只有IOS6设备。

原始问题:

我到处搜寻并尝试了一切,我根本无法解决这个问题!

我有UITextField。选中后,键盘向上滑动,光标在文本字段上开始闪烁。当我点击键盘上的按钮时,一切都正常,键响应,光标停止闪烁。唯一的问题是文本没有放入文本字​​段!然而,它接受来自表情符号键盘的输入。任何帮助将非常感谢!

这就是UITextField的创建方式:

UITextField *userInput = [[UITextField alloc] initWithFrame:CGRectMake(10, yPos, controlWidth, 26)];
yPos += 32;
[userInput setText:[prompt defaultValue]];
[userInput setPlaceholder:[prompt helpText]];
[userInput setBorderStyle:UITextBorderStyleRoundedRect];
[userInput setClearButtonMode:UITextFieldViewModeWhileEditing];
[userInput setFont:[UIFont fontWithName:@"Helvetica" size:18]];
[userInput setAdjustsFontSizeToFitWidth:YES];
[userInput setMinimumFontSize:10];
[userInput setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[userInput setDelegate:self];
[self.scrollView addSubview:userInput];
[self.promptControls addObject:userInput];
[userInput release];

这是for循环,因此UITextField的数量取决于循环被调用的次数。

这些是我使用的委托方法:

- (void)textFieldDidBeginEditing:(UITextField *)aTextField
{
    self.activeField = aTextField;
}

- (void)textFieldDidEndEditing:(UITextField *)aTextField
{
    self.activeField = nil;
}

- (BOOL)textFieldShouldReturn:(UITextField *)aTextField
{
    [aTextField resignFirstResponder];
    return YES;
}

activeField是视图控制器上的一个属性,用于确定当前处于活动状态的字段

我相信这就是所有相关的代码

4 个答案:

答案 0 :(得分:6)

确保在启动时正确设置窗口

你正在打电话

[window setRootViewController:someViewController];

如果你不这样做,那么iOS6中的错误现在......

[window makeKeyAndVisible];

这不是一个错误(忽略),而是把事情扔进了荒芜的土地,似乎导致UITextViewUITextField无效。

如......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

self.viewController = [[[MyViewController alloc] initWithNibName:nil bundle:nil] autorelease];

self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];

[window setRootViewController:navigationController];

[window makeKeyAndVisible];

}

答案 1 :(得分:0)

我不确定,但它可能是一个简单的文字颜色问题。尝试设置文本颜色;

[userInput setTextColor:[UIColor blackColor]];

我希望它有所帮助。

答案 2 :(得分:0)

尝试评论[userInput setDelegate:self];

答案 3 :(得分:0)

这可能是因为窗口文本字段不在关键窗口中。 只有关键窗口才能接受用户输入。 所以,尝试制作[textfield.window makeKeyAndVisible];