2016-03-22 10 views
1

これを尋ねる質問はたくさんありますが、何も試してみませんか?単にUIAlertViewUIAlertViewStylePlainTextInputとしたいのですが、プレースホルダではなくデフォルトのエントリとして、表示されている入力ボックスに所定の文字列がプリロードされています。これは可能ですか?UIAlertVIewのデフォルトテキストが表示されます

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"message" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
[[alert textFieldAtIndex:0] setText:[NSString stringWithFormat:@"%@", @"preloaded string"]]; 
alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
[alert show]; 

上記の例では動作しないsetTextを使用しています。私も試してみました:

だけの利益のため
[[alert textFieldAtIndex:0] setPlaceholder:@"text"]; 

が、これはので、多分、私は他の何かをしないのですでも、プレースホルダが表示されません。

任意のポインタ?

+0

前に 'alertViewStyle'を設定してみてください? – Larme

+4

UIAlertViewはiOS8以降非推奨です。 UIAlertControllerに移動する必要があります。その場合、 'UITextField * alertText1 = alertController.textFields.firstObject;のようにstgを実行できます。 [alertText1 setText @ "Default Txt"]; ' –

+0

@Larme That works - ありがとう。答えとして追加し、私はそれを選択します。 – RGriffiths

答えて

0

あなたはどちらか何をも行うことができますすることUIAlertviewもあるとして(UIAlertControllerを使用することですhereに似UIAlertviewように見えるかSDCAlertView

などのオープンソース実装を使用する独自のカスタム「ポップアップ」ビューを作成する必要がありますそれは100%

0

IOS 8)で非推奨代わりにUIAlertController使用します

let alertController = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) 
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in 
    // Configure UITextField here... 
    textField.placeholder = "Placeholder" 
} 
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (_) -> Void in 
    let textField = alertController.textFields![0] as UITextField 
    let value = textField.text ?? "Untitled" 
    /// Save value here... 
} 
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) 
alertController.addAction(okAction) 
alertController.addAction(cancelAction) 
presentViewController(alertController, animated: true, completion: nil) 
0
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"message" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
[[alert textFieldAtIndex:0] setText:[NSString stringWithFormat:@"%@", @"preloaded string"]]; 
[alert show]; 

を作動さ

UITextField *alert = alertController.textFields.firstObject; 
[alert [email protected]"YOUR ALERT TEXT HERE"]; 
0

あなたは

AlertView

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"sample" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil]; 

    [alert setAlertViewStyle: UIAlertViewStylePlainTextInput]; 
    // Alert style customization 

    [[alert textFieldAtIndex:0] setDelegate:self];  
    [[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad]; 
    [[alert textFieldAtIndex:0] setText:@"Richard"];   
    [[alert textFieldAtIndex:0] setPlaceholder:@"textvalue"]; 

    [alert show]; 

UIAlertControllerようにそれを行うことができます

UIAlertController *alert = [UIAlertController 

           alertControllerWithTitle:@"sample" 

           message:@" " 

           preferredStyle:UIAlertControllerStyleAlert]; 



    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) 

    { 


     [textField setText:@"Richard"]; 
     textField.placeholder = NSLocalizedString(@"textvalue", @"Login"); 


    }]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
// do your action on ok click 

    }]]; 

    [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 


    // do your action on cancel click 
    }]]; 

    UIViewController *viewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; 

    if (viewController.presentedViewController && !viewController.presentedViewController.isBeingDismissed) { 

     viewController = viewController.presentedViewController; 

    } 



    NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:alert.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:viewController.view.frame.size.height*2.0f]; 

    [alert.view addConstraint:constraint]; 



    [viewController presentViewController:alert animated:YES completion:^{ 



    }]; 
関連する問題