因此,我最近为iOS 6开发了一个可读取PDF的应用程序。它在我的iPhone 3GS上运行良好,但是当我在较新版本的Xcode (最初使用4.5,现在使用6.01)为iOS 8重新编译它时,输入您想要加载的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];发布于 2016-06-16 12:31:36
试着遵循代码!!
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];https://stackoverflow.com/questions/37851151
复制相似问题