2009-08-11 9 views
0

連絡先アプリケーションの追加/編集ビューで、フィールドの「Return」キーを押すと、各UITextFieldを順番に表示します。これらのフィールドはUITableViewCell内にあるようです。これを行うには良い方法は何ですか?UITableViewCell内のUITextField間の移動

テーブル内にない一連のUITextFieldがある場合は、 [self.view viewWithTag:tag]を呼び出して、ビューのリストとそれらを循環させるための使用方法を取得できます。しかし、テーブル内では、私は1つのビューを取得し、私はこれを変換する方法がわからない。

-(BOOL)textFieldShouldReturn:(UITextField *)textField { 
    // Find the next entry field 
    for (UIView *view in [self entryFields]) { 
     if (view.tag == (textField.tag + 1)) { 
      [view becomeFirstResponder]; 
      break; 
     } 
    } 

    return NO; 
} 

/* 
Returns an array of all data entry fields in the view. 
Fields are ordered by tag, and only fields with tag > 0 are included. 
Returned fields are guaranteed to be a subclass of UIResponder. 

From: http://iphoneincubator.com/blog/tag/uitextfield 
*/ 
- (NSArray *)entryFields { 
    if (!entryFields) { 
     self.entryFields = [[NSMutableArray alloc] init]; 
     NSInteger tag = 1; 
     UIView *aView; 
     while (aView = [self.view viewWithTag:tag]) { 
      if (aView && [[aView class] isSubclassOfClass:[UIResponder class]]) { 
       [entryFields addObject:aView]; 
      } 
      tag++; 
     } 
    } 
    return entryFields; 
} 

答えて

0

私は何かをブラウズしている間にこれを発見しました。遅れて申し訳ありません。

問題を解決していない場合は、画面に表示されているのと同じ順序でuitextfieldオブジェクトの配列を作成できます。テーブルを作成するときに、テキストフィールドの.tagプロパティを設定します。テキストフィールドdelegateメソッド内で、タグを読み取り、次のフィールドに移動するために1ずつインクリメントして、becomefirstresponder呼び出しを発行します。

また、textFieldDidEndEditingデリゲートメソッドを見ることもできます。

関連する問題