2016-06-02 6 views
0

Ich versuche, einen Textfield-Wert von UIAlertController zu bekommen, aber immer wenn ich versuche, den Wert (Name) einzugeben und auf label anzuzeigen, zeigt die Ausgabe nichts.IOS 9 - Wie bekomme ich einen Wert von textField in einem UIAlertController?

- (IBAction)button:(id)sender { 
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Test" message:@"Please Enter your name " preferredStyle:UIAlertControllerStyleAlert]; 
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
     textField.placeholder = @"Person Name "; 
     textField.textColor = [UIColor blueColor]; 
     textField.clearButtonMode = UITextFieldViewModeWhileEditing; 
     textField.borderStyle = UITextBorderStyleRoundedRect; 
     textField.secureTextEntry = NO; 

    }]; 
    UIAlertAction* yesButton = [UIAlertAction 
           actionWithTitle:@"ENTER, please" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 
            //Handle the ENTER button 
            // how to Display the name in the label 

           }]; 
    UIAlertAction* noButton = [UIAlertAction 
           actionWithTitle:@"No, thanks" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 
            //Handle no button. 
           }]; 


    [alert addAction:yesButton]; 
    [alert addAction:noButton]; 

    [self presentViewController:alert animated:YES completion:nil]; 

} 
+0

den yesButton Hantierungsbausteins für Textfeld Details auf dem Etikett Anzeige verwenden . –

+0

@JP_Mob können Sie bitte einige Code teilen, indem Sie diese Frage beantworten, Vielen Dank für Ihre Zeit –

Antwort

1

Schnell swift Beispiel zog ich aus einem alten Projekt

 alert.addAction(UIAlertAction(title: "Send", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in 
     if let textFields = alert.textFields { 
      if let textField = textFields.first { 

      } 
     } 
    })) 

in Ihrer Anwendung wäre es so etwas wie dies mag:

UIAlertAction* yesButton = [UIAlertAction actionWithTitle:@"ENTER, please" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) 
{ 
    NSArray *textFields = alert.textFields; 
    // Probably smart to do some nil checking here 
    NSLogv(@"%@", textFields.first.text); 
    // add to label like so 
    label.text = textFields.first.text; 
}]; 
+0

Ich habe versucht, NSString anstelle von NSArray zu verwenden, es hat es nicht gefallen –

+0

Nicht sicher, dass ich Ihre Frage verstehe. Das '. Die Eigenschaft textFields ist ein Array. Von dort müssen Sie die erste greifen, wo Sie Ihre Schnur bekommen können. –

+0

also wie kann ich den Wert auf einem Etikett anzeigen. Danke –

Verwandte Themen