0

非常に初心者の obj-c の質問です。

http://uaimage.com/image/c6c9ca23TableViewという 2 つのセクションにグループ化しました。最初のセクションには、 が含まれるカスタム セルがあります。「次へ」、「前へ」(最初のセクションのテキストフィールドを切り替える)、「完了」(キーボードを閉じる)ボタンを追加したキーボード用の入力アクセサリビューを実装する必要がありますhttp://uaimage.com/image/62f08045 .UITextField

質問: 入力アクセサリ ボタンをタップして、TableView の最初のセクションのセル内のテキスト フィールドを切り替える可能性を実装するには、何が必要ですか? セルまたはテキスト フィールドにタグを付ける必要がありますか? その場合、ユーザーが入力アクセサリ ボタンをタップしたときにそれらの値を取得するにはどうすればよいですか? それとも、これを行うためのより良いアプローチですか?

ありがとう、アレックス

4

1 に答える 1

1

tags0 1 と 2の txt 、txt1、txt 2 という 3 つの UITextField があるとします。UITableViewCell *cell.h ファイルに追加 します。

EDIT : 現在の tableView セルからすべての textField の参照を取得するには、次のデリゲート メソッドを追加します。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    cell = nil;
    cell = (UITableViewCell *)[textField superView];
    return YES;
}

Input Accessories の prev ボタン アクションで、次の操作を行います。

-(IBAction)previousBtn:(id)sender
{
   UITextField *txt = (UITextField*)[cell viewWithTag:0];
   UITextField *txt1 = (UITextField*)[cell viewWithTag:1];
   UITextField *txt2 = (UITextField*)[cell viewWithTag:2];
   if(txt.isFirstResponder)
   {
    [txt resignFirstResponder];
    [txt2 becomeFirstResponder];
   }
   else if(txt1.isFirstResponder)
   {
    [txt1 resignFirstResponder];
    [txt becomeFirstResponder];
   }
   else if(txt2.isFirstResponder)
   {
    [txt2 resignFirstResponder];
    [txt1 becomeFirstResponder];
   }
}

入力アクセサリの次のボタン アクションで、次の操作を行います。

-(IBAction)nextBtn:(id)sender
{
   UITextField *txt = (UITextField*)[cell viewWithTag:0];
   UITextField *txt1 = (UITextField*)[cell viewWithTag:1];
   UITextField *txt2 = (UITextField*)[cell viewWithTag:2];

   if(txt.isFirstResponder)
   {
    [txt resignFirstResponder];
    [txt1 becomeFirstResponder];
   }
   else if(txt1.isFirstResponder)
   {
    [txt1 resignFirstResponder];
    [txt2 becomeFirstResponder];
   }
   else if(txt2.isFirstResponder)
   {
    [txt2 resignFirstResponder];
    [txt becomeFirstResponder];
   }
}
于 2012-10-30T09:06:01.510 に答える