Reputation: 214
I have two viewcontrllers. In one there is a tableview with a button at each cell. Onclick on this button another view controller is shown. After performing some functions in that viewcontroller i am dismissing it by calling [self dismissViewContrller animated:YES completion:nil];
Now after it gets dismissed i want to reload the data in tableview of the 1st viewcontroller. Any ideas on how to do it?
I can post the code if requested.
Thank You.
Upvotes: 1
Views: 1820
Reputation: 2387
There are several combinations of ways to do this.
One extra alternative to most the answers already given is to check there is a presentedViewController in viewWillAppear.
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.presentedViewController) {
[self.tableView reloadData];
}
}
Not that big of a deal to check, but if you have a ton of data or something, maybe it could be useful for the extra check.
Upvotes: 0
Reputation: 2006
you can do this by just adding following code in your firstviewcontroller
-(void)viewDidAppear:(BOOL)animated
{
[tableView reloadData];
}
with this you can reload your tableview every time when view apper after dismissing secondviewcontroller
Upvotes: 4
Reputation: 9913
You could do this in viewDidAppear on the view controller with the tableview.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
}
This will force your tableview to reload every time the view controller appears on screen. This is for both the first time it appears (so the table view will reload twice at startup I think), as well as when transitioning back up the navigation stack to this view controller.
Upvotes: 1