2

I am unable to reload data in my table view when I use dismissModalViewControllerAnimated however it works perfect if I use pushViewController.

I am calling reloadData in viewWillAppear.

This is how I am switching views:

- (IBAction)addAction:(id)sender
{
    NSLog(@"Add Button Pressd");
    AddNewDrinks *newView = [[AddNewDrinks alloc] initWithNibName:@"AddNewDrinks" bundle:nil];
    self.addNewDrink = newView;
    [self presentModalViewController:addNewDrink animated:YES];
    [newView release];
}

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

This is what i used to get back to previous view.

- (IBAction)save:(id)sender
{
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    path = [path stringByAppendingPathComponent:@"drinks.plist"];
    NSString *drinkName = self.name.text;
    NSString *drinkIngredients = self.ingredients.text;
    NSString *drinkDirection = self.directions.text;
    NSArray *values = [[NSArray alloc] initWithObjects:drinkDirection, drinkIngredients, drinkName, nil];
    NSArray *keys = [[NSArray alloc] initWithObjects:DIRECTIONS_KEY, INGREDIENTS_KEY, NAME_KEY, nil];
    if(drinkName.length != 0)
    {
        NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
        [self.drinkArray addObject:dict];
        [dict release];
    }
    [self.drinkArray writeToFile:path atomically:YES];    
    [self dismissModalViewControllerAnimated:YES];
}

Unfortunately my table's view data is not reloading.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Varundroid
  • 9,135
  • 14
  • 63
  • 93

3 Answers3

2

From the looks of it, you're writing an edited array to a file, but not reading it back before reloading the table.

In viewWillAppear, try reading the new file into memory, then reloading the table.

Tom Irving
  • 10,041
  • 6
  • 47
  • 63
1

Is viewWillAppear called after dismissing the modal view controller? Is your table a valid object?

Lefteris
  • 14,550
  • 2
  • 56
  • 95
  • yeah viewWillAppear getting a call as soon as i am dismissing the model view controller. And i have checked my table view once more, seems like everything is at right place. – Varundroid Oct 04 '11 at 16:20
  • Thanks for trying to help me. I really appreciate it.:) – Varundroid Oct 04 '11 at 16:26
1

Are you reading from a file the data you are presenting in the tableview?

Rui Peres
  • 25,741
  • 9
  • 87
  • 137