2

I have a problem with my UIAlertView text field using iOS6. The text field shifts all the way to the top. When i use iOS7, the text field is in the right spot. Can someone help me? Here is the code:

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Item?"
                                                  message:nil
                                                 delegate:self
                                        cancelButtonTitle:@"Cancel"
                                        otherButtonTitles:@"Add another", @"Done",nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeWords;
[message show];

The text field appears on the title text (here: Item?)

Mike_NotGuilty
  • 2,253
  • 5
  • 32
  • 64

3 Answers3

1

Actually this can be fixed manually by detecting the system version. Here is the right way to do this in this post

Community
  • 1
  • 1
Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41
1

did you try this :

-(void)willPresentAlertView:(UIAlertView *)alertView {

if ([[[UIDevice currentDevice] systemVersion] floatValue] <7) 

   {
    [alertView setFrame:CGRectMake(17, 30, 286, 280)];
    NSArray *subviewArray = [alertView subviews];
    UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
    [message setFrame:CGRectMake(10, 46, 260, 20)];
    UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
    [cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
    UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
    [savebutton setFrame:CGRectMake(10, 170, 260, 42)];
    UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
    [saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
    UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
    [textfield setFrame:CGRectMake(10, 80, 266, 50)];
    UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
    [placeTF setFrame:CGRectMake(15, 70, 256, 50)];
   }

}
Iphone User
  • 1,930
  • 2
  • 17
  • 26
0

Try this code, it will work.

- (IBAction)showAlert:(id)sender
{
    UIAlertView *alertView = [[UIAlertView alloc] init];

    alertView.delegate = self;
    alertView.title = @"Item?";
    alertView.message = nil;
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;

    [alertView addButtonWithTitle:@"Cancel"];
    [alertView addButtonWithTitle:@"Add another"];
    [alertView addButtonWithTitle:@"Done"];

    [alertView show];
}
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Mavericks
  • 524
  • 3
  • 5
  • it may help you. http://mlk-ios-programming-concepts.blogspot.sg/2013/08/uialertviewstyle-property-of-uialertview.html – Mavericks Dec 13 '13 at 15:13