P233 reloadData not working for me


#1

-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear]; [[self tableView] reloadData]; }

in ItemsViewController.m

I’m having trouble with reloading data into the table view.

When I finish editing and touch the back button, the table view reappears, but the table cell is not updated. However, it will update if I scroll the edited table cell off the screen and back on.

Is this an issue with the simulator? I don’t have access to test on a device yet.


#2

My bad.

I made an error in the detailViewController. I used viewDidDisappear method instead of viewWillDisappear. This stopped the table updating, somehow:

error code

[code]-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:YES];

//clear first responder
[[self view] endEditing:YES];

//save change to item
[item setItemName:[nameField text]];
[item setSerialNumber:[serialNumberField text]];
[item setValueInDollars:[[valueField text] intValue]];

}[/code]

correct code

[code]-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:YES];

//clear first responder
[[self view] endEditing:YES];

//save change to item
[item setItemName:[nameField text]];
[item setSerialNumber:[serialNumberField text]];
[item setValueInDollars:[[valueField text] intValue]];

}[/code]


#3

Don’t feel bad I did a similar thing in itemsViewController with

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear];
    [[self tableView]reloadData];
}

I had


-(void) viewWillDisppear:(BOOL)animated
{
    [super viewWillAppear];
    [[self tableView]reloadData];
}

Thanks for posting it help me find my error.


#4

Glad it helped.

I did it again later with these:

It happens when you don’t pay attention to autocomplete

I wanted:
tableView:didSelectRowAtIndexPath:
but I chose:
tableView:didDeselectRowAtIndexPath:

It took a fair while to realise what I had done. :smiley: