3

I'd like to be able to refresh the table on the master side of my app, based on an action taken in my detail view controller.

In this case, I have an orders table on the left (master) side that drills down to show 3 levels of orders: Open, Held & Sent. So, if I "change" the status of an order (put it on hold, take it off of hold, send it, etc) I'd like to be able to reflect that on the master side. Any ideas?

From an action button in the detail view controller I've tried:

1.

[[appDelegate.splitViewController.viewControllers objectAtIndex:0] reload];

2.

OrdersRootController *orc = [[OrdersRootController alloc] initWithNibName:@"Orders" bundle:nil];
orc = [appDelegate.splitViewController.viewControllers objectAtIndex:0];
[orc.tableView reloadData];

Edit:

I tried to add a notification but it's not working:

I must be missing something. . .

I'm adding an observer in awakeFromNib:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOrders:) name:@"OrderStatusChanged" object:odc];

and posting from the order:

[[NSNotificationCenter defaultCenter] postNotificationName:@"OrderStatusChanged" object:self];`

but the selector specified never fires. . . what am i missing?

Alan Carter
  • 213
  • 5
  • 16

3 Answers3

2

Although you already chose an answer.. Call this anywhere in your DetailView:

UINavigationController *navController = self.splitViewController.viewControllers[0];
MasterViewController *controller = (MasterViewController *)navController.topViewController;
Marc
  • 5,284
  • 5
  • 26
  • 50
1

I would pass a reference (possibly in the AppDelegate) to the table view in the detail view to the master view, and directly call the table reload data.

Or you can use notifications, the master view raises a notification and the detail view responds by loading the appropriate data.

Devraj
  • 2,897
  • 21
  • 25
  • Thought about a notification. Haven't used them much. I'll look into it. . . – Alan Carter Jul 31 '11 at 00:34
  • They are quite simple to use, you can pass custom user data in a dictionary, very handy. – Devraj Jul 31 '11 at 06:55
  • I must be missing something. . . – Alan Carter Jul 31 '11 at 17:39
  • I must be missing something. . . I'm adding an observer in awakeFromNib: `[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOrders:) name:@"OrderStatusChanged" object:odc];` and posting from the order: `[[NSNotificationCenter defaultCenter] postNotificationName:@"OrderStatusChanged" object:self];` but the selector specified never fires. . . what am i missing? – Alan Carter Jul 31 '11 at 17:45
  • Ha! Moved the notification observer to viewDidLoad and it works like a champ! Thanks! @Devraj – Alan Carter Jul 31 '11 at 18:48
0

If you are using the default splitview contoller you can do this

[self.rootViewController.tableView reloadData];
Dmorneault
  • 199
  • 1
  • 8