简体   繁体   English

在细节之后更新表视图数据

[英]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.

相关问题 从Segue接收数据后,View Controller不会更新 - View Controller does not update after receiving data from a segue ios:如何以编程方式从细节到表格视图进行筛选 - ios: How to segue from detail to table view programmatically 从表视图控制器Segue到主从控制器 - Segue to Master Detail Controller from Table View Controller 从替换详细信息控制器的表视图单元格中搜索不会触发 - segue from table view cells that replace detail controller do not fire 详细信息视图UITableView-在筛选之前传递数据 - Detail View UITableView - Pass data before segue 当按下地图视图注释时,如何使用segue在详细视图中显示来自plist的数据 - how to display data from plist in detail view using segue when map view annotation is pressed TableViewController不会选择详细视图 - TableViewController will not segue to detail view 如何在表视图中选择后将数据传递到详细视图? - How to pass data to detail view after being selected in a table view? 如何根据表视图单元格的详细文本标签,将segue设置为与表视图控制器不同的视图控制器? - How can I set a segue to a different view controller from a table view controller, based on the detail text label of the table view cell? 从plist在segue中传递数据。 表视图到详细信息视图 - Passing data in segue from plist. Table view to Details View
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM