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:
[[appDelegate.splitViewController.viewControllers objectAtIndex:0] reload];
and
OrdersRootController *orc =开发者_StackOverflow社区 [[OrdersRootController alloc] initWithNibName:@"Orders" bundle:nil];
orc = [appDelegate.splitViewController.viewControllers objectAtIndex:0];
[orc.tableView reloadData];
I tried to add a notification but it's not working.
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?
Although you already chose an answer.. Call this anywhere in your DetailView:
UINavigationController *navController = self.splitViewController.viewControllers[0];
MasterViewController *controller = (MasterViewController *)navController.topViewController;
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.
If you are using the default splitview contoller you can do this
[self.rootViewController.tableView reloadData];
精彩评论