私は Objective-C と iOS アプリの開発にかなり慣れていないので、私の質問に対する答えが単純である場合は申し訳ありません。あるビュー コントローラーから別のビュー コントローラーに GTGift オブジェクトのポインターを送信しようとしています。次のコードを入力すると、オブジェクトが送信され、2 番目のビュー コントローラーのインスタンス変数に格納されます。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
GTGift *selectedGift = [[[GTGiftStore sharedStore] allGifts] objectAtIndex:[indexPath row]];
GTDetailViewController *dvc = [[self storyboard] instantiateViewControllerWithIdentifier:@"detailVC"];
[dvc setDetailGift:selectedGift];
[[self navigationController] pushViewController:dvc animated:YES];
}
ただし、最初のView Controllerにこのコードを入力すると:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
gift = [[[GTGiftStore sharedStore] allGifts] objectAtIndex:[indexPath row]];
GTDetailViewController *dvc = [[self storyboard] instantiateViewControllerWithIdentifier:@"detailVC"];
[[self navigationController] pushViewController:dvc animated:YES];
}
そして、2番目のView Controllerのこのコード:
- (void)viewWillAppear:(BOOL)animated {
GTGiftsViewController *gvc = [[self storyboard] instantiateViewControllerWithIdentifier:@"giftsVC"];
detailGift = [gvc gift];
NSLog(@"%@", detailGift);
}
detailGift は null を返します。
その理由を一生理解することはできません。機能しないコード セグメントと同様のアプローチを使用できれば、アプリケーションにとってはるかに実用的です。誰かが私のためにこのトピックに光を当てたり、同じタスクを完了するために別の方向に向けたりすることができれば、本当に感謝しています!