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
Here is a cleaner implementation of a UIAlertView coupled with a UITextField: DDAlertPrompt or EGOTextFieldAlertView.
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).
Open the xib
file, click on the UIView
and make sure that the "User Interaction Enabled
" check box is ticked.
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.
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];
}
}