Cell.miでは、辞書にいくつかの文字列を追加するために次のコードを記述しています。
- (void)textViewDidEndEditing:(UITextView *)textView {
if (cellIndex == 0) {
[[dataSource objectAtIndex:dataIndex] setObject:self.cellTextView.text forKey:@"Usersmell"];
}
if (cellIndex == 1) {
[[dataSource objectAtIndex:dataIndex] setObject:self.cellTextView.text forKey:@"Usertaste"];
}
if (cellIndex == 2) {
[[dataSource objectAtIndex:dataIndex] setObject:self.cellTextView.text forKey:@"Usersuits"];
}
if (cellIndex == 3) {
[[dataSource objectAtIndex:dataIndex] setObject:self.cellTextView.text forKey:@"Usernotes"];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Objects.plist"];
//removed some code here that gets the index of dictionary for replacement, then:
[allObjectsArray replaceObjectAtIndex:index withObject:[NSDictionary dictionaryWithDictionary:[dataSource objectAtIndex:dataIndex]]];
[allObjectsArray writeToFile:path atomically:YES];
}
そして、TableViewController.mで:
-(IBAction)doneButtonPressed:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
これで、ユーザーは、オブジェクトに関する情報とユーザーが追加した新しい情報を含むDetailViewControllerに戻ります。情報は、viewWillAppearのplistから抽出されます。
ただし、問題は、ユーザーが最初にキーボードを閉じずに[完了]ボタンを押すと(textViewDidEndEditingがトリガーされる)、最後に編集されたセルのテキストがDetailViewControllerに表示されないことです。
ただし、ユーザーがもう1ステップ戻ってから、オブジェクト(DetailViewController)を再入力すると、テキストはそこにあります。そのため、textViewDidEndEditingのトリガーが遅すぎて、親ビューのviewWillAppearが、[完了]ボタンが押されたときにテキストを取得できません。
これを解決する方法は?