objective-c在后退导航后重新加载UITableView

时间:2013-07-11 21:08:22

标签: objective-c uitableview navigation reload nsnotification

我在TableViewController中嵌入了NavigationController,在某些时候我使用Seguepush到新的ViewController。当我从ViewController导航回来时,我想重新加载tableView中的TableViewController

我按照herehere发布的解决方案。由于某种原因,它不起作用。我想念一些东西,但此刻我看不到它。

有没有胶水,为什么代码不起作用?我需要做些什么才能让它发挥作用?

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];

}

2 个答案:

答案 0 :(得分:1)

这不能回答你的问题“为什么代码不起作用?”,但最简单 导航回到它时可以重新加载表视图的方法 在reloadData中致电viewWillAppear

答案 1 :(得分:0)

我怀疑上面的代码不起作用,因为没有调用initWithStyle。在那里设一个断点来测试我的理论。如果是这种情况,则将该代码移至viewDidLoad。