2016-06-16 28 views
0

所以我最近做了一個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]; 
+0

在你的情況是設置alert.alertViewStyle = UIAlertViewStylePlainTextInput;這將爲您添加一個文本字段。您可以使用UITextField * textField = [alertView textFieldAtIndex:0];在UIAlertView委託回調中訪問它。 –

回答

0

曾嘗試下面的代碼的代碼!

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

歡迎..如果答案對你有用,請豎起大拇指...... –