そこで私は、電話番号を管理するときに連絡先アプリで標準の Apple コードが機能する方法をエミュレートしようとしています。具体的には、テーブルビューが空で、ユーザーが他の行に移動した場合にテーブルビューから行を削除することに取り組んでいます
私の問題は、テーブルビューのリロードにより UITextField がレスポンダーを辞任するため、ユーザーがナビゲートしたテキスト フィールドのレスポンダーを再度設定する必要があることです。
私は UITextField デリゲートを持っており、通常の処理を行っていますtextFieldShouldBeginEditing , textFieldDidBeginEditing , textFieldShouldEndEditing , textFieldDidEndEditing
機能を処理するために、私のコードは内textFieldDidEndEditing
にあります。これにより、テーブルビュー配列からデータを削除し、テーブルビューには2つのセクションがあるため、次を呼び出しています:
[MyTableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
次textFieldDidBeginEditing
を使用して、編集中の textField の indexPath を保存します。
EditableCustomCell *textFieldCell = (EditableCustomCell *)[[textField superview] superview];
NSIndexPath *indexPath = [MyTableView indexPathForCell:(EditableCustomCell *)textFieldCell];
responderIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
次に、次のコードを使用して、正しい行の textField をファーストレスポンダーに設定します。
EditableCustomCell *customCell = (EditableCustomCell *)[MyTableView cellForRowAtIndexPath:responderIndexPath];
[customCell.editableTextField becomeFirstResponder];
処理の終わり近くまではすべて問題ないように見えますが、突然textFieldDidBeginEditing
indexPath のセクション 0 行 0 が返され始めます (タグ値または含まれているテキストを調べると、テキスト フィールドの正しい値が返されます)。
以下は、上記で説明したプロセスの開始からのログです。
- textFieldDidEndEditing started <-- start of delete processing
- textFieldDidEndEditing - tableviewData - replacing object at index 1
CustomTableViewController.deleteRow - delete called for indexPath section 1 ... row 1
- reloading MyTableView
- CustomTableViewController-cellForRowAtIndexPath started
CustomTableViewController-cellForRowAtIndexPath section=1 row=0
CustomTableViewController-cellForRowAtIndexPath ending
CustomTableViewController-cellForRowAtIndexPath section=1 row=1
CustomTableViewController-cellForRowAtIndexPath ending
CustomTableViewController-cellForRowAtIndexPath section=1 row=2
CustomTableViewController-cellForRowAtIndexPath ending
- textFieldShouldBeginEditing started
indexPath for textFieldShouldBeginEditing is : section 1 row 1
- textFieldShouldBeginEditing ending
- textFieldDidBeginEditing started
indexPath for textFieldDidBeginEditing is : section 1 row 1 text 3 tag 1
- textFieldDidBeginEditing ending
- textFieldDidEndEditing ending <-- end of delete processing
- textFieldDidBeginEditing started
- textFieldDidBeginEditing ... setting responderIndexPath section 0 row 0
indexPath for textFieldDidBeginEditing is : section 0 row 0 text 123 tag 0
- textFieldDidBeginEditing ending
ログの最後の部分からわかるように、textFieldDidEndEditing
完了後にtextFieldDidBeginEditing
が呼び出されますが、セクション 0 と行 0 が返されます (行はずっと表示され、表示されたままになります)
これが呼び出される理由も、正しい indexPath が返されない理由もわかりません。ご覧のとおり、テキストが値 (この場合は入力された値 123) に対して返され、他のデータと他の行 (テキスト フィールドのテキストとタグの両方) でこれを確認しました。
becomeFirstReponsder
withinの設定textFieldDidEndEditing
が間違っているのかもしれませんが、それが本当なら、これをどこで処理するか途方に暮れています
これをよりよく理解している誰かが私を助けてくれることを願っています.
ありがとうイジー
EDIT 1: コードでは、呼び出されるのはすべて完了becomeFirstReponder
する前です。textFieldDidEndEditing
が完了した後にログを見ると、cellForRowAtIndexPath
削除されたばかりの行の下にあった行に対して 1 回、次に indexPath のセクション/行に対して 0 を返すときに、テキストフィールドに 2 回入力して存在します。このポスト テーブル リロード メソッドの起動を引き起こしているイベントのシーケンスを理解できていません
EDIT 2: それは私だけですか、それともログの最後にtextfieldSHOULDbeginEditing
NOがないのは本当に奇妙に思えますか? textFieldDidBeginEditing
中にテーブルをリロードして内部プロセスを台無しにしているのtextFieldDidEndEditing
ですか?これを行うためのより良い場所はありますか (つまり、行を削除し、テーブルビューをリロードして UI の更新を表示します)?