0

I am trying to create a UIAlertView which allows you to write comments but the fields do not appear on the AlertView. here the code:

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

a image sample:

AlertView Sample

Could anybody help me out? Thanks

1 Answers1

0

UIAlertView is deprecated as of iOS8. Also, it's not intended to be customized in this way: The view hierarchy for this class is private and must not be modified. (from the docs).

I would suggest either using one of the many replacement libraries like SDCAlertView or rolling your own comment dialog.

If you must use UIAlertView, set the alertViewStyle to UIAlertViewStyleLoginAndPasswordInput and change the password text field to show text using field.secureTextEntry = NO;

Gereon
  • 17,258
  • 4
  • 42
  • 73