當我使用dismissModalViewControllerAnimated
時,我無法在我的表格視圖中重新載入數據,但是如果我使用pushViewController
,它的工作原理是完美的。如何在我們使用dismissModalViewControllerAnimated重新加載數據以返回到前一個視圖?
我打電話reloadData
在viewWillAppear
。
這是怎麼了切換視圖:
- (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];
}
這是我用來找回以前的觀點。
- (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];
}
不幸的是我的表格視圖數據沒有重新加載。
現在正在工作。謝謝 :) – Varundroid