gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:51:36 25 4
gpt4 key购买 nike

我正在尝试将 uitextfield 添加到我的 alterview。当用户尝试输入文本时,alterview 应该向上移动一点,这样键盘就不会重叠,当按下完成键时,键盘应该消失,alertview 应该向后移动。

在 iOS 3.1.2(以及 3.2)中运行它时一切正常,但是当我尝试在 iOS 4 中运行它时,alertview 显示在错误的位置并且键盘不会消失。有什么建议么?这是我的代码:

- (void)addItemAction{

workoutName = [[UIAlertView alloc] initWithTitle:@"New Workout" message:@"Insert the name of your new workout:\n " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil];
workoutName.cancelButtonIndex = 0;
UITextField *titleField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 90.0, 260.0, 25.0)];
titleField.delegate = self;
titleField.borderStyle = UITextBorderStyleRoundedRect;
titleField.returnKeyType = UIReturnKeyDone;
[workoutName addSubview:titleField];
[workoutName show];


}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {


[textField resignFirstResponder];
return YES;

}

- (void)textFieldDidBeginEditing:(UITextField *)textField {

[UIView beginAnimations:nil context:NULL];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, -70.0);
[workoutName setTransform:myTransform];
[UIView commitAnimations];

}

- (void)textFieldDidEndEditing:(UITextField *)textField {

[UIView beginAnimations:nil context:NULL];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 0.0);
[workoutName setTransform:myTransform];
[UIView commitAnimations];
self.newWorkout = textField.text;

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

if (buttonIndex == 1) {
if (self.newWorkout != @"TestWorkout"){
[self.workoutPlanArray insertObject:[NSDictionary dictionaryWithObjectsAndKeys:self.newWorkout, @"titleValue", @"04.08.10", @"dateValue", nil] atIndex:counter];
counter++;
[self.tableView reloadData];
}
}


}

最佳答案

我也在我的应用程序中使用带有文本字段的 alertview,在 iOS 4.0 上也是如此。 它工作正常。

这是示例代码:_

-(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];
}

您也可以引用以下两个在键盘通知上调用的方法。

-(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];

}
}

关于iphone-sdk : Adding a textfield to UIAlertview does not work in iOS 4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3410372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com