2016-04-07 9 views
0

Ich versuche, ein UIAlertView zu erstellen, mit dem Sie Kommentare schreiben können, die Felder jedoch nicht in AlertView angezeigt werden. hier der Code:UIAlertView mit Textfeld keine Felder anzeigen

UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Your opinion" 
               message:@"Enter your comment" // IMPORTANT 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"Send", nil]; 



textField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)]; 
[textField setBackgroundColor:[UIColor blackColor]]; 
[textField setPlaceholder:@"Name"]; 
textField.keyboardAppearance = UIKeyboardAppearanceAlert; 
textField.delegate = self; 
[prompt addSubview:textField]; 

textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 50.0)]; 
[textField2 setBackgroundColor:[UIColor whiteColor]]; 
[textField2 setPlaceholder:@"Your comment"]; 
textField2.keyboardAppearance = UIKeyboardAppearanceAlert; 
textField2.delegate = self; 

lblCounter = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 120, 10)]; 
lblCounter.backgroundColor = [UIColor clearColor]; 
lblCounter.textColor = [UIColor whiteColor]; 
lblCounter.font = [UIFont systemFontOfSize:13.5]; 

lblCounter.text = @"0/100 characters"; 

[prompt addSubview:textField2]; 
[prompt addSubview:lblCounter]; 


[prompt show]; 

ein Bild Beispiel:

AlertView Sample

Kann mir jemand helfen? Danke

Antwort

0

UIAlertView ist ab iOS8 veraltet. Es ist auch nicht beabsichtigt, auf diese Weise angepasst zu werden: (aus der Dokumentation).

Ich würde vorschlagen, entweder eine der vielen Ersatzbibliotheken wie SDCAlertView oder Rolling Ihre eigenen Kommentar-Dialog.

Wenn Sie Muss Verwendung UIAlertView, stellen Sie den alertViewStyle zu UIAlertViewStyleLoginAndPasswordInput und das Passwort Textfeld ändern Text zu zeigen, mit field.secureTextEntry = NO;