将文本添加到Alertview文本域iOS中

时间:2014-03-24 17:59:32

标签: ios uitextfield uialertview

当警报视图显示时,我希望文本字段中已有现有文本。这是我的代码,我必须添加什么?

        UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
        [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];

        // Change keyboard type
        [[dialog textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeDefault];

        [dialog show];

3 个答案:

答案 0 :(得分:2)

UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[[dialog textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeDefault];

[[dialog textFieldAtIndex:0]setText:@"Your string here"];

[dialog show];

答案 1 :(得分:1)

UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
        [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[[dialog textFieldAtIndex:0]setText:@"YourText"];
        // Change keyboard type
        [[dialog textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeDefault];

        [dialog show];

答案 2 :(得分:-1)

我在黑暗中拍摄,但试试看         dialog.textfield.text = @“Blah blahddy blah” 把它放在[dialog show]之前。