4

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
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
  • Just call `[self.tableView reloadData]` . Does it work for you? What do you mean by reference the current UITableView? – vodkhang Jul 21 '10 at 15:06
  • 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 Jul 21 '10 at 15:09
  • Updated my post, my UITableView is managed by a seperate controller – Sheehan Alam Jul 21 '10 at 15:16

3 Answers3

30

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];
}
John Topley
  • 113,588
  • 46
  • 195
  • 237
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
3

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

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
0

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]; }
David Gao
  • 906
  • 4
  • 12
  • 23