ユーザーがいくつかの矢印キーでテキストフィールドをナビゲートできるようにするtableViewがあります。ただし、ユーザーがテーブルの一番上にいる場合、ファーストレスポンダーが実際に変更される前に、矢印ボタンを 2 回押す必要があります。最初のクリックで次のセルが表示され、2 回目のクリックで実際には上のセルの textField にフォーカスが移動します。他のすべての方向と矢印は、フォーカスが変更され、スクロールが発生するワンクリックで機能します。ユーザーが一番下にいる場合を除きます。同じことが起こります。(ただし、ユーザーがテキストフィールドを選択したときにスクロールを一番上に設定しているため、ユーザーはこれを行うことができません)
テーブルの上にいても同じ視覚効果を得る方法はありますか?
私のコード...
switch (arrowButton.tag) {
case UpArrow:
destinationIndex = [NSIndexPath indexPathForRow:currentIndex.row - 1 inSection:currentIndex.section];
newTag = currentTextField.tag;
break;
case LeftArrow:
// Move back one textField.
if (currentTextField.tag == CustomerDetailsOrderViewControllerCellLeftTextField) {
// Selected text field is on left. Select right textfield in the row above
destinationIndex = [NSIndexPath indexPathForRow:currentIndex.row - 1 inSection:currentIndex.section];
newTag = CustomerDetailsOrderViewControllerCellRightTextField;
} else {
// Selected text field is on right. Select the left textfield in the same row
destinationIndex = currentIndexPath;
newTag = CustomerDetailsOrderViewControllerCellLeftTextField;
}
break;
case RightArrow:
// Move forward one textField.
if (currentTextField.tag == CustomerDetailsOrderViewControllerCellLeftTextField) {
// Selected text field is on Left. Select right textfield
destinationIndex = currentIndexPath;
newTag = CustomerDetailsOrderViewControllerCellRightTextField;
} else {
// Selected text field is on right. Select the left textfield in the row below
destinationIndex = [NSIndexPath indexPathForRow:currentIndex.row + 1 inSection:currentIndex.section];
newTag = CustomerDetailsOrderViewControllerCellLeftTextField;
}
break;
case DownArrow:
destinationIndex = [NSIndexPath indexPathForRow:currentIndex.row + 1 inSection:currentIndex.section];
newTag = currentTextField.tag;
break;
default:
break;
}
[_tableView scrollToRowAtIndexPath:destinationIndex atScrollPosition:UITableViewScrollPositionNone animated:YES];
newTextFieldSelection = (UITextField *)[[_tableView cellForRowAtIndexPath:destinationIndex] viewWithTag:newTag];
[newTextFieldSelection becomeFirstResponder];