我正在嘗試將uitextfield
添加到我的alterview
。當用戶嘗試輸入文本時,alterview
應該稍微向上移動一點,這樣鍵盤不會重疊,按下完成鍵後,鍵盤應該消失,alertview
應該移回。iphone-sdk:將文本框添加到UIAlertview不適用於iOS 4?
在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];
}
}
}