UITextField 未出现在 iOS8
UITextField not appearing in iOS8
所以我最近为 iOS 6 制作了一个阅读 PDF 的应用程序。它在我的 iPhone 3GS 上运行良好,但是当我在较新版本的 Xcode 中为 iOS 8 重新编译它时(最初使用 4.5,现在使用 6.01)用于输入名称的文本字段您要加载的 PDF 文件不再出现在应有的位置。
当用户按下打开时,有问题的文本字段出现在警告框中。
这是在 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];
所以我最近为 iOS 6 制作了一个阅读 PDF 的应用程序。它在我的 iPhone 3GS 上运行良好,但是当我在较新版本的 Xcode 中为 iOS 8 重新编译它时(最初使用 4.5,现在使用 6.01)用于输入名称的文本字段您要加载的 PDF 文件不再出现在应有的位置。
当用户按下打开时,有问题的文本字段出现在警告框中。
这是在 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];