[英]Update table view data after segue from detail
I have got a problem. 我有一个问题。 I need to update data of master view data on segue from detail view.
我需要从详细视图更新segue上的主视图数据。 I've tried to implement prepareForSegue method, but it's not called on tapping back button.
我试图实现prepareForSegue方法,但是没有调用后退按钮。
What's the way i can do that? 我能做到这一点的方式是什么?
Prepare for segue doesn't get called when popping a view controller from the navigation stack. 从导航堆栈弹出视图控制器时,不会调用准备segue。 I'd suggest calling
[tableView reloadData]
either in the detail view's viewWillDisappear
method, or in the master view's viewWillAppear
method. 我建议在详细视图的
viewWillDisappear
方法或主视图的viewWillAppear
方法中调用[tableView reloadData]
。 Alternatively, if you want to reload your table view after making a change, you can try using notifications. 或者,如果要在进行更改后重新加载表视图,可以尝试使用通知。 Something like the following in your master view controller:
类似于主视图控制器中的以下内容:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh:) name:@"RefreshMasterNotification" object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)refresh:(NSNotification *)notification
{
[tableView reloadData];
}
And something like the following whenever you make a change in your detail view controller: 每当您在详细视图控制器中进行更改时,类似下面的内容:
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshMasterNotification"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.