Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh UITableView after app comes becomes active again?

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
like image 615
Sheehan Alam Avatar asked Nov 28 '22 05:11

Sheehan Alam


2 Answers

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];
}
like image 56
Aaron Saunders Avatar answered Nov 29 '22 17:11

Aaron Saunders


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

like image 21
Ole Begemann Avatar answered Nov 29 '22 18:11

Ole Begemann