How to refresh UITableView after app comes becomes active again?

柔情痞子 提交于 2019-11-27 16:54:43

问题


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

回答1:


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];
}



回答2:


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




回答3:


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]; }


来源:https://stackoverflow.com/questions/3300694/how-to-refresh-uitableview-after-app-comes-becomes-active-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!