0

uitableview内に国の値を入力するためのuitextfieldがあります。そのフィールドをタップすると、国の値がロードされたテーブルビューが表示されます。

任意のセルをタップすると、同じフォームに戻り、国フィールド内に選択した値が追加されます。つまり、選択した値を viewwillappear メソッド内のテキスト フィールドに割り当てます。国フィールド内にテキストを設定した後。キーボードを辞任したいので、resignFirstResponderを追加しましたが、キーボードを辞任していません。

以下は私のコードです:

 - (void)textFieldDidBeginEditing:(UITextField *)textField;
    {
      if( textField == self.myCountryField ){

        aCountryListView = 
            [[LCCountryListViewController alloc]init]; 

        UINavigationController *navigationController = 
            [[UINavigationController alloc] 
             initWithRootViewController:aCountryListView];

        [self presentModalViewController:navigationController animated:YES];

      }
    }
-(void)viewWillAppear:(BOOL)animated{
//-----------------------------------

  self.myCountryField.text = aCountryListView.mySelectedCountry;

  [self.myCountryField resignFirstResponder];

  [[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification object:nil];

  [[NSNotificationCenter defaultCenter] addObserver:self 
  selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath 
//-------------------------------------------------------------------------------
{  
  static NSString *CellIdentifier = @"PoetNameCell";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (cell == nil) 
  {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

   cell.backgroundColor = [UIColor clearColor];

    if( indexPath.row == 0 ){

      UILabel *aLblTitle = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 220, 30)];
      aLblTitle.backgroundColor = [UIColor clearColor];
      aLblTitle.font = [UIFont fontWithName:@"Palatino-Bold" size:16.0];
      aLblTitle.text = NSLocalizedString(@"Country","Country");
      aLblTitle.textColor = [UIColor whiteColor];
      [cell.contentView addSubview:aLblTitle];

      myCountryField = [[UITextField alloc]initWithFrame:CGRectMake(133,5,150,30)];
      myCountryField.backgroundColor = [UIColor whiteColor];
      myCountryField.delegate = self;
      myCountryField.borderStyle = UITextBorderStyleRoundedRect;

      [cell.contentView addSubview:myCountryField];
    }
  return cell;
}
4

3 に答える 3

1

以下のコードを使用してください。お役に立てば幸いです。

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

  [self.view endEditing:YES];

  return YES;
}

デリゲートをに接続することを確認してfileownerくださいxib-file。またはviewDidload、次のコードを使用します。

yourtextfield.delegate=self;

.hファイルで使用する<UITextfielddelegate>

于 2013-02-14T13:31:43.003 に答える
0

UITextFieldデリゲートを追加すると、次のコードが機能することを願っています

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

  [self.myCountryField resignFirstResponder];

  return YES;
}
于 2013-02-14T11:34:32.830 に答える
0

代わりにこれを使用するのはどうですか:

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)
                                           to:nil
                                         from:nil
                                     forEvent:nil];
于 2013-02-14T11:52:30.570 に答える