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];
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…