1

UITableviewのカスタムセルにTextFieldがあります。TableviewはMainViewの下部にあるため、CustomCellキーボードでTextFieldをクリックすると、テキストフィールドが非表示になります。下の画像は問題を示しています。

ここに画像の説明を入力してください

ここに、MainViewにUITextFieldがある場合に機能するコードがあります。UITextfieldをクリックすると、ビュー全体のアニメーションが必要になるため、以下のコードを編集してください。

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

if (textField.tag > 0) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-165.0,
                                 self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}   

   }
 -(void)textresign{

[[self.view viewWithTag:1]resignFirstResponder];
   }
-(void)textFieldDidEndEditing:(UITextField *)textField {         
if (textField.tag > 0) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view .frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+165.0,
                                  self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}   

  }

しかし、カスタムセルUITextFieldの修正方法がわかりませんでした。ヘルプが適用されます。

4

1 に答える 1

5

ここにコードがあります、コードを少し変更する必要があります

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

    if (textField.tag > 0)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationBeginsFromCurrentState:YES];
        self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-165.0,
                                     self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];
    }
}

の代わりに、キーボードの辞任でビューを再配置するには、以下の方法を使用して textFieldDidEndEditingください。

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

    if (textField.tag > 0)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationBeginsFromCurrentState:YES];
        self.view .frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+165.0,
                                      self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];

    }
    [textField resignFirstResponder];
    return YES;
}

以下の方法を使用すると、デリゲートをテキストフィールドに設定する必要があります。

私はあなたが解決策を得ることができることを願っています。

于 2012-11-12T15:07:57.250 に答える