4
votes

I would like my UITableView to reloadData once my app is active again, after a user exits the application. I know I need to implement (in my app delegate):

- (void)applicationDidBecomeActive:(UIApplication *)application

but im not sure how to reference the current UITableView?

UPDATE: My UITableView is a separate controller. It is actually presented as follows

AppDelegate > Root View Controller > Pushes UITabBarController modally which has a UITableViewController
3
Just call [self.tableView reloadData] . Does it work for you? What do you mean by reference the current UITableView? - vodkhang
i think more information about how the tableView is created, is it in the rootdelegate or a seperate controller? this would be helpful in providing an answer - Aaron Saunders
Updated my post, my UITableView is managed by a seperate controller - Sheehan Alam

3 Answers

30
votes

following up on Ole's answer above

add this when initializing the viewcontroller

[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(becomeActive:)
    name:UIApplicationDidBecomeActiveNotification
    object:nil];

add the actual method in the controller

- (void)becomeActive:(NSNotification *)notification {
    NSLog(@"becoming active");
}

be sure to clean up the notification

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
3
votes

If you can't access your view controller from the app delegate, you could also have your controller listen to the UIApplicationDidBecomeActiveNotification notification.

0
votes

you can create your class called TableViewManager. in there register list of UITableView so that you can refresh any table you want. it's like this, in yourTableViewManager class, you have a method called

- (void)RefreshTableView:(UITableView *)tableView {
if(tableView != nil)
    [tableView reloadData]; }