xcode iPad 从详细视图刷新主数据。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6886702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPad refresh Master data from detail view.
提问by Alan Carter
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?
在这种情况下,我在左侧(主)侧有一个订单表,可以向下钻取以显示 3 个级别的订单:未结、保留和已发送。因此,如果我“更改”订单的状态(搁置、取消搁置、发送等),我希望能够在主端反映这一点。有任何想法吗?
From an action button in the detail view controller I've tried:
从我尝试过的详细视图控制器中的操作按钮:
1.
1.
[[appDelegate.splitViewController.viewControllers objectAtIndex:0] reload];
2.
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:
我在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?
但指定的选择器永远不会触发。. . 我错过了什么?
采纳答案by Devraj
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.
我会将详细视图中的表视图的引用(可能在 AppDelegate 中)传递给主视图,并直接调用表重新加载数据。
Or you can use notifications, the master view raises a notification and the detail view responds by loading the appropriate data.
或者你可以使用通知,主视图发出通知,细节视图通过加载适当的数据来响应。
回答by Marc
Although you already chose an answer.. Call this anywhere in your DetailView:
尽管您已经选择了一个答案.. 在您的 DetailView 中的任何位置调用它:
UINavigationController *navController = self.splitViewController.viewControllers[0];
MasterViewController *controller = (MasterViewController *)navController.topViewController;
回答by Dmorneault
If you are using the default splitview contoller you can do this
如果您使用默认的 splitview 控制器,您可以执行此操作
[self.rootViewController.tableView reloadData];

