2

我已将其范围缩小到仅 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 循环中,因此UITextFields 的数量取决于循环被调用的次数。

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

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

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

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

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

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

4

4 回答 4

6

Ensure that you are setting up your window correctly at launch

And that you are calling

[window setRootViewController:someViewController];

Which is now an error in iOS6 if you dont and...

[window makeKeyAndVisible];

Which isn't an error (to omit) but throws things into wierd land and seems to result in UITextView and UITextField not working well.

as in...

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

}
于 2012-10-16T17:52:21.460 回答
0

尝试评论[userInput setDelegate:self];

于 2013-02-27T12:40:25.640 回答
0

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

[userInput setTextColor:[UIColor blackColor]];

我希望它有所帮助。

于 2012-10-16T14:19:43.273 回答
0

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

于 2014-11-27T09:46:08.317 回答