[英]How to go back to previous controller and refreshing that controller after saving
我在视图控制器中有一个表视图。 当我想向表视图中添加某些内容时,请按添加按钮,然后转到详细信息视图控制器,其中有一个保存按钮。 现在,我想回到我的tableviewcontroller并在按下保存按钮后刷新它。
我将数据发送到外部数据库而不是核心数据中。
由于您使用的是modalViewController,因此点击Save按钮后 ,您可以关闭它并刷新数据,在这种情况下,您将需要使用NSNotification 。
尝试以下代码:
在包含tableview的视图控制器内部,
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableReload) name:@"tableReload" object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"tableReload" object:nil];
}
-(void)tableReload{
[self.tableView reloadData];
}
在第二个视图控制器中,IBAction为保存按钮
[[NSNotificationCenter defaultCenter]postNotificationName:@"tableReload" object:nil];
[self dismissViewControllerAnimated:YES completion:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.