Reputation:
Is there a 'shorter' way to write it ? seems to be a long way to get the playersViewController instance ...
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UITabBarController *tabBarController = (UITabBarController *)window.rootViewController;
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:0];
PlayersViewController *playersViewController = [[navigationController viewControllers] objectAtIndex:0];
[playersViewController.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
I am refreshing the an already loaded tableView
#pragma mark - RatePlayerViewControllerDelegate
- (void)ratePlayerViewController: (RatePlayerViewController *)controller didPickRatingForPlayer:(Player *)player
{
if (player.rating != self.requiredRating)
{
// do stuff.. in self.tableView
// refresh players tableView
Upvotes: 0
Views: 86
Reputation: 2722
You could use notification
PlayersViewController.m
add this line in your init method :
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadPlayers:) name:@"reloadPlayersNotification" object:nil];
and implement the method
- (void)reloadPlayers:(NSNotification *)notification {
[self.tableView reloadData];
}
Remember to remove your observer when your tableView must not receive reloadData call (for example if the tableView is not visible)
[[NSNotificationCenter defaultCenter] removeObserver:self name@"reloadPlayersNotification" object:nil]
and now if you want to reload this tableView from another class :
[[NSNotificationCenter defaultCenter] postNotification:@"reloadPlayersNotification"];
Upvotes: 1
Reputation: 5674
If you want to reload your UITableView
simply use [self.tableView reloadData]
EDIT: One thing to remember as well, you should always update views on the main thread. Im not sure what you're doing exactly, but it never hurts to be safe rather than sorry. The following would reload your tableView on the main thread.
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
Upvotes: 0