Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload data in parent UITableViewController from Modal ViewController

I have a navigation controller with a root view controller (UITableViewController). This table view controller has a modal segue to another navigation controller with a UITableViewController as the root view controller. From my modal table view controller, I am calling

[self dismissModalViewControllerAnimated:YES];

to dismiss the model view. I am trying to, prior to dismissing the modal view, call my "refresh" function (which is located in the first UITableViewController). I tried using

[self.parentViewController refresh];

but I am guessing that I am then referring to the navigation controller of the modal view? It doesn't seem to be working for that reason.

like image 268
jrble819 Avatar asked Mar 20 '12 20:03

jrble819


1 Answers

Create an NSNotificationCenter in your parent view:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh) name:@"updateParent" object:nil];

Then call it when you dismiss the modal view:

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateParent" object:nil];
like image 193
WrightsCS Avatar answered Oct 21 '22 09:10

WrightsCS