<legend id='Z2161'><style id='Z2161'><dir id='Z2161'><q id='Z2161'></q></dir></style></legend>

    <bdo id='Z2161'></bdo><ul id='Z2161'></ul>
  • <small id='Z2161'></small><noframes id='Z2161'>

      <i id='Z2161'><tr id='Z2161'><dt id='Z2161'><q id='Z2161'><span id='Z2161'><b id='Z2161'><form id='Z2161'><ins id='Z2161'></ins><ul id='Z2161'></ul><sub id='Z2161'></sub></form><legend id='Z2161'></legend><bdo id='Z2161'><pre id='Z2161'><center id='Z2161'></center></pre></bdo></b><th id='Z2161'></th></span></q></dt></tr></i><div id='Z2161'><tfoot id='Z2161'></tfoot><dl id='Z2161'><fieldset id='Z2161'></fieldset></dl></div>

      <tfoot id='Z2161'></tfoot>
      1. iphone-sdk:向 UIAlertview 添加文本字段在 iOS 4 中不起作用?

        时间:2023-10-23
          <tfoot id='LASeH'></tfoot>
          <i id='LASeH'><tr id='LASeH'><dt id='LASeH'><q id='LASeH'><span id='LASeH'><b id='LASeH'><form id='LASeH'><ins id='LASeH'></ins><ul id='LASeH'></ul><sub id='LASeH'></sub></form><legend id='LASeH'></legend><bdo id='LASeH'><pre id='LASeH'><center id='LASeH'></center></pre></bdo></b><th id='LASeH'></th></span></q></dt></tr></i><div id='LASeH'><tfoot id='LASeH'></tfoot><dl id='LASeH'><fieldset id='LASeH'></fieldset></dl></div>

          <small id='LASeH'></small><noframes id='LASeH'>

            <tbody id='LASeH'></tbody>
            <bdo id='LASeH'></bdo><ul id='LASeH'></ul>

              <legend id='LASeH'><style id='LASeH'><dir id='LASeH'><q id='LASeH'></q></dir></style></legend>

                  本文介绍了iphone-sdk:向 UIAlertview 添加文本字段在 iOS 4 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

                  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 so the keyboard does not overlap and when pressing the done key the keyboard is supposed to disappear and the alertview should shift back.

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

                  It all works fine when run it in iOS 3.1.2 (and also in 3.2) but as soon as I try to run it under iOS 4 the alertview is displayed in the wrong position and the keyboard won't disappear. Any suggestions? Here is my code:

                  - (void)addItemAction{
                  
                  workoutName = [[UIAlertView alloc] initWithTitle:@"New Workout" message:@"Insert the name of your new workout:
                                  " 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 上也是如此.它工作正常.

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

                  这里是示例代码:_

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

                  这篇关于iphone-sdk:向 UIAlertview 添加文本字段在 iOS 4 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <small id='oGMoQ'></small><noframes id='oGMoQ'>

                  1. <i id='oGMoQ'><tr id='oGMoQ'><dt id='oGMoQ'><q id='oGMoQ'><span id='oGMoQ'><b id='oGMoQ'><form id='oGMoQ'><ins id='oGMoQ'></ins><ul id='oGMoQ'></ul><sub id='oGMoQ'></sub></form><legend id='oGMoQ'></legend><bdo id='oGMoQ'><pre id='oGMoQ'><center id='oGMoQ'></center></pre></bdo></b><th id='oGMoQ'></th></span></q></dt></tr></i><div id='oGMoQ'><tfoot id='oGMoQ'></tfoot><dl id='oGMoQ'><fieldset id='oGMoQ'></fieldset></dl></div>
                      <tbody id='oGMoQ'></tbody>
                      <bdo id='oGMoQ'></bdo><ul id='oGMoQ'></ul>

                        • <legend id='oGMoQ'><style id='oGMoQ'><dir id='oGMoQ'><q id='oGMoQ'></q></dir></style></legend>
                          <tfoot id='oGMoQ'></tfoot>