UIAlertView mit Texteingabefeldern |
|
|
|
Geschrieben von: Philipp
|
THURSDAY, 05 FEBRUARY 2009 15:08 |
Machmal möchte man Texteingaben mal eben schnell in einem modalen Dialog erhalten. Dies wird mit der undokumentierten Methode addTextFieldWithValue erledigt. Folgender Code Zeigt ein Beispiel:
// undokumentierte Methoden nutzen
@interface UIAlertView (extended)
- (UITextField *) textFieldAtIndex: (int) index;
- (void) addTextFieldWithValue: (NSString *)value label:(NSString *)label;
@end
// alert view erstellen
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle: @"Überschrift"
message:@"Text"
delegate:self
cancelButtonTitle:@"Abbrechen"
otherButtonTitles:@"OK", nil];
// Texteingabefelder hinzufügen
[myAlert addTextFieldWithValue:@"" label:@"Hinweistext"];
[myAlert addTextFieldWithValue:@"vorbelegter Text" label:@""];
// Texteingabefelder konfigurieren
UITextField *textfield = [myAlert textFieldAtIndex:0];
textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
textfield.keyboardType = UIKeyboardTypeAlphabet;
textfield.keyboardAppearance = UIKeyboardAppearanceAlert;
textfield.autocapitalizationType = UITextAutocapitalizationTypeWords;
textfield.autocorrectionType = UITextAutocorrectionTypeNo;
textfield = [myAlert textFieldAtIndex:1];
textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
textfield.keyboardType = UIKeyboardTypeURL;
textfield.keyboardAppearance = UIKeyboardAppearanceAlert;
textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
textfield.autocorrectionType = UITextAutocorrectionTypeNo;
[myAlert show];
Unter der Voraussicht, das kein Messagetext der UIAlertView hinzugefügt wird, lassen sich so bis zu 3 Textfelder vernüftig darstellen, danach ist dar Alert-Dialog einfach zu klein durch die Darstellung der Tastatur.
|
LAST_UPDATED2 |