UITextField没有出现在iOS8中
问题描述:
所以我最近做了一个iOS 6的应用程序,它读取PDF文件。它在我的iPhone 3GS上运行良好,但是当我在新版本的Xcode(最初使用4.5,现在使用6.01)中重新编译iOS 8时,输入您要加载的PDF名称的文本字段不再显示在它的位置应该。UITextField没有出现在iOS8中
当用户按下打开时,问题中的文本字段出现在警告框内。
继承人它在iOS 6中
alert = [[UIAlertView alloc]initWithTitle:@"Please enter a valid PDF name below:" message:@"(Please add .PDF on the end!) \n \n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ok", nil];
textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
[textField setBackgroundColor:[UIColor whiteColor]];
textField.delegate = nil;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.placeholder = @"PDF name";
textField.tintColor = [UIColor colorWithRed:98.0/255.0f green:98.0/255.0f blue:98.0/255.0f alpha:1.0];
textField.keyboardAppearance = UIKeyboardAppearanceAlert; //set up an alert box with a text feild
[textField becomeFirstResponder];
[alert addSubview:textField];
[alert show];
[alert release];
答
曾尝试下面的代码的代码!
UIAlertController * alertView= [UIAlertController
alertControllerWithTitle:@"Please enter a valid PDF name below:"
message:@"Please add .PDF on the end!"
preferredStyle:UIAlertControllerStyleAlert];
[alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"PDF name";
}];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Handel your yes please button action here
UITextField *textField = alertView.textFields[0];
NSString *pdfName = textField.text;
NSLog(@"PDF Name: %@",pdfName);
[alertView dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* noButton = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Handel no, thanks button
[alertView dismissViewControllerAnimated:YES completion:nil];
}];
[alertView addAction:yesButton];
[alertView addAction:noButton];
[self presentViewController:alertView animated:YES completion:nil];
+0
完美的作品,非常感谢。 – Jobalisk
+0
欢迎..如果答案对你有用,请竖起大拇指...... –
在你的情况是设置alert.alertViewStyle = UIAlertViewStylePlainTextInput;这将为您添加一个文本字段。您可以使用UITextField * textField = [alertView textFieldAtIndex:0];在UIAlertView委托回调中访问它。 –