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

ser*_*_ov 3 tableview ios

我有一个问题.我需要从详细视图更新segue上的主视图数据.我试图实现prepareForSegue方法,但是没有调用后退按钮.

我能做到这一点的方式是什么?

Kam*_*ros 6

从导航堆栈弹出视图控制器时,不会调用准备segue.我建议[tableView reloadData]在详细视图的viewWillDisappear方法中调用,或者在主视图的viewWillAppear方法中调用.或者,如果要在进行更改后重新加载表视图,可以尝试使用通知.类似于主视图控制器中的以下内容:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

每当您在详细视图控制器中进行更改时,类似以下内容:

[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshMasterNotification"];
Run Code Online (Sandbox Code Playgroud)