我在TableViewController
中嵌入了NavigationController
,在某些时候我使用Segue
到push
到新的ViewController
。当我从ViewController
导航回来时,我想重新加载tableView
中的TableViewController
。
我按照here和here发布的解决方案。由于某种原因,它不起作用。我想念一些东西,但此刻我看不到它。
有没有胶水,为什么代码不起作用?我需要做些什么才能让它发挥作用?
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// notification when comeing back from the cameraView
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMagazine:) name:@"reloadTable" object:nil];
}
return self;
}
//[...]
// notification reload
-(void)reloadMagazine:(NSNotification *)notification {
NSLog(@"notification reload");
[self.tableView reloadData];
}
//[...]
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTable" object:self];
}
-(void)uploadData:(id)sender {
// Upload and navigate back to the tableViewController
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTable" object:self];
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}
答案 0 :(得分:1)
这不能回答你的问题“为什么代码不起作用?”,但最简单
导航回到它时可以重新加载表视图的方法
在reloadData
中致电viewWillAppear
。
答案 1 :(得分:0)
我怀疑上面的代码不起作用,因为没有调用initWithStyle。在那里设一个断点来测试我的理论。如果是这种情况,则将该代码移至viewDidLoad。