【发布时间】:2013-07-10 07:48:28
【问题描述】:
我在NavigationController 中嵌入了一个TableViewController,在某些时候我使用Segue 到push 到一个新的ViewController。当我从ViewController 导航回来时,我想在TableViewController 中重新加载tableView。
我遵循here 和here 发布的解决方案。由于某种原因,它不起作用。我想念一些东西,但我现在看不到它。
谁有胶水,为什么代码不起作用?我该怎么做才能让它工作?
TableViewController.m
- (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];
}
ViewController.m
-(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];
}
【问题讨论】:
-
你为什么不直接打电话给
reloadDatainviewWillAppear? -
当然你不应该同时调用dismissViewControllerAnimated 和popViewControllerAnimated。坚持前者。
-
... 你应该在某处移除观察者,可能在
dealloc。 -
我认为导航返回时不会调用
viewWillAppear。会试试这个。 -
与
viewWillAppear合作。谢谢。删除dismissViewControllerAnimated,popViewControllerAnimated单独工作正常。反之则不行。
标签: objective-c uitableview navigation reload nsnotification