NavigationController 階層の 2 つの Views 部分があります。1 つはアイテムのリストを表示し、2 つ目はアイテムを編集したり、新しいアイテムを追加したりできます。
親ビューでは、ナビゲーションバーの右側に追加ボタンがあり、一度押すと、ID「AddChild」でセグエが実行されます。また、ユーザーがテーブル アイテムをタップすると、「EditChild」という ID を持つ別のセグエが実行され、すべてストーリーボードに設定されます。
ユーザーが親ビュー (項目のリストを含む) に到達したが、項目がまだ存在しない場合、プログラムで "AddChild" セグエを実行したいので、親ビューコントローラーの viewWillAppear: に次のコードを追加しました。
// if there are no children, send user to add screen
if (self.childListData.count == 0) {
[self performSegueWithIdentifier:@"AddChild" sender:self];
}
子ビューコントローラーは正常に読み込まれますが、ナビゲーション項目は以前のビューのままです ([戻る] ボタンと [保存] ボタンの代わりに [戻る] ボタンと [追加] ボタン)。
これは私の prepareForSegue: メソッドです:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get a reference to our detail view
ChildDetailTableViewController *childDetail = (ChildDetailTableViewController *)[segue destinationViewController];
// Pass the managed object context to the destination view controller
childDetail.managedObjectContext = managedObjectContext;
// If we are editing a child we need to pass some stuff, so check the segue title first
if ([[segue identifier] isEqualToString:@"EditChild"])
{
// Get the row we selected to view
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// Pass the child object from the table that we want to view
childDetail.currentChild = [childListData objectAtIndex:selectedIndex];
}
}
何が足りないのかわからないので、誰か助けていただければ幸いです。