Question

When the alert view shows up I want to have existing text already within the textfield. This is my code, what must I add?

        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];
Était-ce utile?

La solution

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];

Autres conseils

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];

I'm taking a shot in the dark here, but try dialog.textfield.text = @"Blah blahddy blah" Put it before [dialog show].

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top