How to reload UITableViews after returning from a dismissmodalView
I have an app that loads three tables with data from arrays that are loaded from core data on startup. The user can tap a button to pull up another page with which they can edit the stored information. When they are finished, their changes are stored and committed back to core data and the user is returned to the home page to hopefully view their changes. However, the data is not reloaded into the tables. I've tried [srcTableView reloadData]; with no luck.
The way it works is that the tables are populated from arrays that are loaded from core data when called from viewWillAppear. I can see that the right information is being stored in the array, but the array, but when the reloadData method is called, there is no change. When the app is restarted however, the appropriate data IS in the tables. I'm guessing it's some sort of instance issue, where the instance of the tables that I'm reloading is not the instance that is displaying...somehow or another. I'm not really sure how to tell.
-Added
I've tried the reloadData to no effect. Here's some code:
Instantiating tables
In -loadView
setTable = [[[MPIViewController alloc] initWithFrame:CGRectMake(kFrameX, 0, 1024, 768) TableData1:Data1 TableData2:Data2 TableData2:Data3]autorelease];
Opening second view:
-(IBAction)O开发者_JAVA百科penOptions:(id)sender{
// Create the modal view controller
MPIViewController *viewController = [[MPICreateViewController alloc] initWithNibName:@"MPICreateViewController" bundle:nil];
// We are the delegate responsible for dismissing the modal view
viewController.delegate = self;
// Create a Navigation controller
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:viewController];
// show the navigation controller modally
[self presentModalViewController:navController animated:YES];
// Clean up resources
[navController release];
[viewController release];
}
- (void)didDismissModalView {
// Dismiss the modal view controller
[self dismissModalViewControllerAnimated:YES];
}
I've created the protocol for the modalViewControllerDelegate as well. Not sure what code would be most effective to post other than this.
Your view controller will get a -viewWillAppear:
message when the modal view controller covering it is about to be dismissed. That’s usually where you should put a call to -reloadData
. In other words:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[srcTableView reloadData];
}
You need to make sure, though, that srcTableView
is actually being set somewhere; from the looks of it, you’re instantiating another view controller—MPIViewController—in your -loadView
, which is unorthodox and probably not what you want to be doing.
you can use the `[srcTableView reloadData]; in viewWillAppear method
精彩评论