Note that there are some explanatory texts on larger screens.

plurals
  1. POtableView: didSelectRowAtIndexPath: inconsistency
    primarykey
    data
    text
    <p>I'm fairly new to Objective-C and iOS app development so I apologize if the answer to my question is simple. I'm trying to send a pointer of a GTGift object from one view controller to another. When I enter the following code, the object is send and stored in an instance variable of the second view controller:</p> <pre><code>- (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]; } </code></pre> <p>However, when I enter this code in the first view controller:</p> <pre><code>- (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]; } </code></pre> <p>And this code in the second view controller:</p> <pre><code>- (void)viewWillAppear:(BOOL)animated { GTGiftsViewController *gvc = [[self storyboard] instantiateViewControllerWithIdentifier:@"giftsVC"]; detailGift = [gvc gift]; NSLog(@"%@", detailGift); } </code></pre> <p>detailGift returns null.</p> <p>I can't for the life of me understand why, and it would be much more practical for my application if I could use an approach similar to the code segment that does not work. If anyone can shine some light on this topic for me or point me in a different direction to complete the same task I would really appreciate it!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload