1

i'm having a couple of problems when i try to alloc a UITextView on an AlertView. Here is my code:

UIAlertView* minhaCritica = [UIAlertView new];
minhaCritica.title = @"7Arte";
[minhaCritica addButtonWithTitle:@"Cancelar"];
[minhaCritica addButtonWithTitle:@"Enviar"];
minhaCritica.message = @"Escreve a tua crítica:\n\n\n\n";
minhaCritica.delegate = self;
[minhaCritica show];

CGRect frame = minhaCritica.frame;
frame.origin.y -= 100.0f;
minhaCritica.frame = frame;

criticaTxtView = [UITextView alloc];
[criticaTxtView setFont:[UIFont systemFontOfSize:16.0f]];
[criticaTxtView initWithFrame:CGRectMake(20.0, 80.0, 245.0, 40.0)];
[minhaCritica addSubview:criticaTxtView];
[criticaTxtView becomeFirstResponder];

my problem is when i start inputing text, the text view doesn't scroll as i type. It should scroll one line up, when the first 2 rows are full.

Can anyone help me with this? Here's a video showing the problem: http://www.welove.com.pt/7arte.swf

Also, i'm having trouble getting the text the user inputed into a fiel. i worked with: criticaText = [[alertView textField] text]; but now it doesn't work with the code above.

2 Answers 2

7

I think you're trying to solve the wrong problem. According to the API docs, an Alert View is used "to display an alert message to the user." You shouldn't be using it for input. Use a modal view or something similar instead.

Following the UI conventions of a platform is generally good practice and not doing so here could get your application rejected by Apple.

3
  • 1
    Unfortunately the “UI convention” here seems to be to display the usual blue bubble with an input field. Apple does it all the time. That’s precisely the reason all developers are trying to stick input field into UIAlertView; the only problem here is caused by Apple keeping the text field private API.
    – zoul
    Commented Jun 8, 2010 at 13:07
  • Agreed with zoul... all you have to do to see this is make an HTML page and make a link that does a Javascript "alert('...');" with a whole lotta text in the '...'. You'll see Safari do exactly what the poster is asking about.
    – Steve
    Commented Aug 17, 2010 at 0:58
  • In 2008/9 this wasn't as common (only the App Store/iTunes login as far as I can remember) but even Apple does it a lot now. So much so that, in iOS5, they added an API where you can add up to two UITextFields. I still think that trying to add a UITextView would be a mistake. Commented Apr 10, 2012 at 17:50
4

It sounds like the relatively benign undocumented UIAlertView API's aren't being allowed anymore, so whether you're using a text field or a text label, you're going to need to use a different mechanism. I'd recommend the following blog posts are good examples of how to address this issue:

Custom UIAlertView (Color chooser)

Embedding UITables into UIAlertViews

Alert View with Prompt

These techniques appear to be legitimate from an App Store perspective and address how to embed any sorts of controls into alert views.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.