0

Iphone でサンプル Web アプリケーションを作成しています...そのアプリケーションのメイン ページはログイン ページです....ユーザーはテキスト フィールド (UITextField) にユーザー名とパスワードを入力し、プログラムによって検証されます。

私の問題は、キーボードで押されたタブキーを使用して、ある uitextfield から別の uitextfield にカーソルを移動したいことです (Windows 操作のように)。

これどうやってするの?

4

1 に答える 1

1

以下を呼び出して、フォーカスを特定の UITextField に移動できます。

[myTextField becomeFirstResponder]

次のメソッドを宣言してクラスに UITextFieldDelegate を実装すると、キーボードで押された "Done" キーを処理できます。これは、タブを押すのと同等の iPhone ネイティブ アプリです。

/*****************************************************************************/
/* Handle the Done button being pressed on the keyboard for any of our       */
/* editable UITextFields.  We either pass the keyboard focus to the next     */
/* text field, or we hide the keyboard.                                      */
/*****************************************************************************/
- (BOOL)textFieldShouldReturn:(UITextField *)xiTextField 
{        
  if (xiTextField == myAccountNameTextField]) 
  {
    NSLog(@"Done pressed whilst in account name field, pass focus");
    [myPasswordTextField becomeFirstResponder];
  }
  else
  {
    NSLog(@"No next text field, closing keyboard");
    [xiTextField resignFirstResponder];  
  }
}
于 2009-10-23T14:55:24.417 に答える