iphone-sdk: Adding a textfield to UIAlertview does not work in iOS 4?

前端 未结 5 1104
无人及你
无人及你 2020-12-19 12:40

I am trying to add uitextfield to my alterview. When the user tries to enter text the alterview is supposed to shift up a little bit s

相关标签:
5条回答
  • 2020-12-19 13:11

    Here is a cleaner implementation of a UIAlertView coupled with a UITextField: DDAlertPrompt or EGOTextFieldAlertView.

    0 讨论(0)
  • 2020-12-19 13:15

    I have no clue (yet) regarding the positioning of the alert, but you might try sending resignFirstResponder in your textFieldShouldReturn implementation to the alertView.

    Also, that should make the keyboard disappear (even if I do not know exactly why).

    0 讨论(0)
  • 2020-12-19 13:20

    Open the xib file, click on the UIView and make sure that the "User Interaction Enabled" check box is ticked.

    0 讨论(0)
  • 2020-12-19 13:31

    I had this problem that is new in iOS 4 as well. I tried to do a translation on it and realized that it doesn't matter the translation, only that a translation was called.

    myAlert = my AlertView
    CGAffineTransform rotate = CGAffineTransformMakeTranslation(0.0f, 0.0f);
    myAlert.transform = rotate;
    [myAlert show];
    [myAlert release];
    

    There must be a callback that gets fired from the translation but this fixes the problem. It should act as it did in pre-iOS 4.0.

    0 讨论(0)
  • 2020-12-19 13:38

    I am also using alertview with a textfield in my application, & that too on ioS 4.0. Its working fine.

    Here is the sample code:_

    -(void)showAlert{
    
    showAlert=YES; //boolean variable
    
    createNewAlert =[[UIAlertView alloc] initWithTitle:@"ADD item" message:@"Put it blank textfield will cover this" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    
    UITextField *txtName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
    txtName.text=@"";
    [txtName setBackgroundColor:[UIColor whiteColor]];
    [txtName setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [txtName setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    [txtName setTextAlignment:UITextAlignmentCenter];
    [createNewAlert addSubview:txtName];
    
    
    [createNewAlert show];
    }
    

    Also you can refer the following two methods which are called on Keyboard notifications.

    -(void)keyboardWillShow: (id) notification {
    
    if(showAlert==YES)
    {
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [createNewAlert setTransform:CGAffineTransformMakeTranslation(0,-60)];
        [createNewAlert show];
        [UIView commitAnimations];
    }
    

    }

    -(void)keyboardWillHide: (id) notification {
    
    if(showAlert==YES) 
    {
    
    
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.3];
            [createNewAlert setTransform:CGAffineTransformMakeTranslation(0,+60)];
    
            [UIView commitAnimations];
    
    }
    }
    
    0 讨论(0)
提交回复
热议问题