Refresh table from another UIViewController

ios, objective-c, uitableview, uiviewcontroller

Solution

Option 1

@Class2

@property (nonatomic) BOOL shouldRefresh; // in .h file

- (void)viewWillAppear:(BOOL)animated // in .m file
{
    [super viewWillAppear:animated];
    if (_shouldRefresh) [self.tableView reloadData];
}

@Class1

// Add this in any method where you want it to refresh and push to view
ClassTwoController *viewController = [[ClassTwoController alloc] init];
[viewController setShouldRefresh:YES];
[self.navigationController pushViewController:viewController animated:YES];

*UPDATE:

Option 2

@Class 2

// Add this line in viewDidLoad in same class you want the tableView to refresh
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshTableWithNotification:) name:@"RefreshTable" object:nil];

// Add this method just beneath viewDidLoad:
- (void)refreshTableWithNotification:(NSNotification *)notification
{
    [self.tableView reloadData];
}

@Class1

// Call this when ever you want to refresh the tableView in Class2
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshTable" object:nil userInfo:nil];

Problem

I have two view controllers one of them (`ViewController`) has a table called `tableView`. I would like to refresh this table from my other view controller (`pageView`). I have tried this in the `pageView`: ``` ViewController*refresh; [refresh.tableView reloadData]; ``` But this is not working. The connecting segue between the two view controllers is a push segue What should I do? Should I do it through a storyboard segue?

Original source

Related problems