Frage

I have a TableViewController embedded in a NavigationController, at some point I use a Segue to push to a new ViewController. When I navigate back from the ViewController I want to reload the tableView in the TableViewController.

I followed the solution posted here and here. For some reason it does not work. I miss something but I can't see it at the moment.

Has anybody a glue, why the code does not work? What do I have to do to get it work?

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

}
War es hilfreich?

Lösung

This does not answer your question "why the code does not work?", but the easiest method to reload the table view when navigating back to it could be to call reloadData in viewWillAppear.

Andere Tipps

I suspect that the code above does not work because initWithStyle is not being called. Put a breakpoint there to test my theory. If that is the case, then move that code to viewDidLoad.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top