views:

200

answers:

3

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
+2  A: 

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
Can you show me an example of how I can use UIApplicationDidBecomeActiveNotification in my view controller?
Sheehan Alam
A: 

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
+2  A: 

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(@″becomming active″);
}

be sure to clean up the notification

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
Aaron Saunders
what happens when this is run on anything but an iPhone 4?
Sheehan Alam
You may need to do some macro if else for different iphone version
vodkhang
How can I determine what phone version the user is running?
Sheehan Alam
this really is a new question....http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/model
Aaron Saunders