简体   繁体   中英

reloading tableView of one view controller from a pushed view controller

I've got a Parse background block that uploads some data. This occurs in a view controller (lets call it addDataViewController ) that was pushed onto another view controller (where my table view is, lets call that tableViewController ). I need to reload that tableView when the data finishes uploading. Ive got a navigation controller embedded in my storyboard so ive tried doing

//In addDataViewController
//when the data finishes uploading
self.navigationController.viewControllers objectAtIndex:0];

but for some reason the viewController stack was nil .

Then I tried referencing tableViewController as a property of the addDataViewController in prepare for segue of tableViewController . I added a tableViewController property to my h file of addDataViewController

//in prepare for segue of tableViewController
dataViewController.tableViewController = self;

then referenced that objects tableView and called reloadData , but nothing seemed to happen

[self.tableViewController.tableView reloadData];

I thought for sure that would have worked, but it didnt. Any ideas?

one approach is to use notifications. in your addDataViewController you would fire a notification, when the update is done:

[[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateDone" object:nil];

in your tableViewController you would subscribe to the notification in viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(doSomething)
                                             name:@"UpdateDone"
                                           object:nil];

and then:

-(void)doSomething {
    [self.tableView reloadData];
}

If you are importing view controller then you must use [self.addChildViewController:tableViewController.view];

hope this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM