UITextField inside an UIAlertView not working in iOS4.1 and works in 3.0

后端 未结 3 514
闹比i
闹比i 2021-01-25 01:13

I have a UITextField added to an UIAlerView (Kind of adding user to list with nick name, and nickname is asked by the alertview.). Thats work perfect in iOS3, But I cant type to

3条回答
  •  被撕碎了的回忆
    2021-01-25 02:02

    In iOS 4 UIAlertViews will automatically be moved and sized to avoid the keyboard if they contain any UITextFields in their subviews so you don't have to move it yourself. Simply add a text field like so:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello"
                                                    message:@"Tap below to enter text:\n\n"
                                                   delegate:nil
                                          cancelButtonTitle:@"Dismiss"
                                          otherButtonTitles:nil];
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 68, 260, 30)];
    [textField setBorderStyle:UITextBorderStyleRoundedRect];
    [alert addSubview:textField];
    [textField release];
    [alert show];
    [alert release];
    

    Be sure to add \n's to make room for your text field, you'll have to play around with getting the field in the correct position.

提交回复
热议问题