Varundroid
Varundroid

Reputation: 9234

How to reloadData when we use dismissModalViewControllerAnimated to get back to previous view?

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.

Upvotes: 2

Views: 943

Answers (3)

Tom Irving
Tom Irving

Reputation: 10069

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.

Upvotes: 2

Rui Peres
Rui Peres

Reputation: 25917

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

Upvotes: 1

Lefteris
Lefteris

Reputation: 14677

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

Upvotes: 1

Related Questions