Doing Steps In Wrong Order - How I Debugged


#1

I’m posting this because I’m absolutely proud of myself for actually understanding this stuff. I never thought I would start to get it but I think I am (somewhat).

So here’s what I goofed up on, and here’s how I debugged it.

Basically I got to the point where you were supposed to be able to click on a row and see the details of the possession. It wasn’t working. All of the fields were null in the ItemDetail view.

So I added NSLog’s to follow the application flow and here’s what it was doing.

I realized it was getting to ItemDetailViewController’s viewWillAppear: first with a null posession, and THEN it was setting detailViewController.possession in ItemsViewController.

Well this was my code (I wasn’t paying attention and I typed it in the wrong location)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ItemDetailViewController *detailViewController = [[[ItemDetailViewController alloc] init] autorelease];
    [[self navigationController] pushViewController:detailViewController 
                                           animated:YES];
    
    NSArray *possessions = [[PossessionStore defaultStore] allPossessions];
    detailViewController.possession = [possessions objectAtIndex:[indexPath row]];
    
    NSLog(@"Possession in ItemsViewController's tableView:didSelectRowAtIndexPath method: %@", detailViewController.possession);
}

Took me a few NSLog’s and a second to realize but, I was pushing the ItemDetailViewController BEFORE I was setting detailViewController’s possession. Stupid me!

I reordered it as below, and it’s working like a champ!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ItemDetailViewController *detailViewController = [[[ItemDetailViewController alloc] init] autorelease];
    NSArray *possessions = [[PossessionStore defaultStore] allPossessions];
    detailViewController.possession = [possessions objectAtIndex:[indexPath row]];
    [[self navigationController] pushViewController:detailViewController 
                                           animated:YES];
}

I just wanted to post this because in making mistakes and figuring them out on my own, I feel like I learn the most. Granted this was a pretty easy one to solve, but at first I was like “Crap, what did I screw up” and I didn’t want to redo the entire chapter, or copy and paste the solution. So I buckled down, and fixed it myself.


#2

Thanks for this. My views were coming up empty as well and I had done the same thing.

Just created my account now to say thanks to you and to the BNR team for keeping this forum alive. It’s resolved my issues EVERY time I’ve been stuck.

//Henrik