【发布时间】:2014-11-18 19:02:59
【问题描述】:
UITextField 在 iOS8 中不起作用,单击文本框时我看不到键盘,也没有看到任何崩溃。但它在 iOS7 设备上运行良好。
我正在使用以下代码:
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"TF_MSG_ ENTER", @"") message:@"\n\n" delegate:self cancelButtonTitle:NSLocalizedString(@"TF_CANCEL_TEXT", @"") otherButtonTitles:NSLocalizedString(@"TF_MSG_ OK", @""), nil];
UITextField *txBookmarkName = nil;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)
{
txBookmarkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0f, 45.0f, 260.0f, 25.0f)];
myAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
txBookmarkName = [myAlert textFieldAtIndex:0];
}
else
{
txBookmarkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0f, 45.0f, 260.0f, 25.0f)];
IF_PRE_IOS4 (
[txBookmarkName release], txBookmarkName = nil;
txBookmarkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0f, 65.0f, 260.0f, 25.0f)];
);
}
[txBookmarkName setDelegate:self];
[txBookmarkName setText:nameLabel.text];
myAlert.tag=TF_TAG_TEXT_FIELD_RENAME;
[txBookmarkName setBorderStyle:UITextBorderStyleRoundedRect];
[txBookmarkName becomeFirstResponder];
[txBookmarkName setAutocorrectionType:UITextAutocorrectionTypeNo];
txBookmarkName.tag=TF_TAG_TEXTFIELD;
[myAlert addSubview: txBookmarkName];
[myAlert setFrame:CGRectMake(0, 0, 300,50)];
IF_PRE_IOS4 (
CGAffineTransform t = CGAffineTransformMakeTranslation(0.0f, 85.0f);
[myAlert setTransform: t];
);
[myAlert show];
[txBookmarkName release];
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0)
[myAlert release];
请帮助我。
提前致谢。
【问题讨论】:
-
你在用模拟器来测试这个吗?
-
它不能在模拟器和设备中工作......
-
UITextField 的 userInteractionEnabled 和 enabled 属性是否设置为 YES?
-
哪个设备,哪个版本的 iOS 8(例如 beta,GM?)。
-
这个代码示例有很多错误,尤其是它包含了适用于早期 iOS 版本的 if 语句。能不能瘦下来。您还应该为一个文本字段尝试一个简单的测试用例,而不是在一个新项目中进行其他尝试。你应该看到 UITextFields 工作得很好。
标签: ios objective-c iphone cocos2d-iphone ios8