3

The UIAlertView message doesn't show properly when the text field in it is being edited (when the keyboard is being displayed). Here's how it looks like: enter image description here

When the keyboard isn't there: enter image description here

This is the code that creates the alert view:

        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Title"
                                  message:@"Enter a name for your recipe"
                                  delegate:self
                                  cancelButtonTitle:@"Cancel"
                                  otherButtonTitles:@"OK", nil];
        [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
        [alertView show];

Is there a way to change the size of some components of the view so that it fits properly in the screen when the keyboard is displayed?

Edit: I just discovered that the alert view becomes scrollable when the keyboard appears. So if you scroll down, you can see the message. But I didn't notice that the first time the alert view popped up, and other users might not either. For now, I'm using what Visput suggested.

Moon Cat
  • 2,029
  • 3
  • 20
  • 25

1 Answers1

0

It is standard behavior for iOS. You could see the same layout in "Photos" application when create new Album in landscape mode.
I think the best way in this situation: place all text to message but title set to nil.
In your case:

UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:nil
                              message:@"Title: Enter a name for your recipe"
                              delegate:self
                              cancelButtonTitle:@"Cancel"
                              otherButtonTitles:@"OK", nil];
Vlad Papko
  • 13,184
  • 4
  • 41
  • 57
  • "Other variant is manually layout subviews in UIAlertView object but it could result to getting **a lot** of bugs" I want to emphasize this a little more. You do **not** want to do this. – Scott Berrevoets Apr 21 '14 at 14:08
  • I was mistaken, it seems that impossible to manually layout UIAlertView in ios7 (it was possible in ios6). That's why you could think about using custom implementation of AlertView. See this topic for details: http://stackoverflow.com/questions/18729220/uialertview-addsubview-in-ios7. I also removed part of my answer that suggests to use custom layout. – Vlad Papko Apr 21 '14 at 14:32
  • It's still possible, but as you found out, it is a major hassle, has the potential for app rejection, and is very prone to issues. I'd strongly discourage anyone to go down that path. Like you said, a custom alert view implementation is a lot easier. – Scott Berrevoets Apr 21 '14 at 14:36