2010-07-21 68 views
4

我想我的UITableView到reloadData,一旦我的应用程序在用户退出应用程序后再次处于活动状态。我知道我需要实现(在我的应用程序委托):如何在应用程序出现后刷新UITableView再次变为活动状态?

- (void)applicationDidBecomeActive:(UIApplication *)application

但林不知道如何引用当前的UITableView?

更新: 我的UITableView是一个单独的控制器。它实际上是呈现如下

AppDelegate > Root View Controller > Pushes UITabBarController modally which has a UITableViewController 
+0

只需调用'[self.tableView reloadData]'。对你起作用吗?引用当前的UITableView是什么意思? – vodkhang 2010-07-21 15:06:13

+0

我想了解更多关于如何创建tableView的信息,它是在rootdelegate还是单独的控制器中? 这将有助于提供答案 – 2010-07-21 15:09:46

+0

更新我的帖子,我的UITableView由一个单独的控制器管理 – 2010-07-21 15:16:26

回答

30

方法在OLE的回答以上

跟进初始化视图 - 控制时,添加此

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

中添加实际的方法控制器

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

一定要清理通知

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

如果在除iPhone 4之外的任何设备上运行,会发生什么情况? – 2010-07-21 16:18:45

+0

你可能需要做一些宏,如果不同的iphone版本 – vodkhang 2010-07-21 16:23:35

+0

如何确定用户正在运行的电话版本? – 2010-07-21 16:55:13

3

如果您不能访问从应用程序的委托您的视图控制器,你也可以有你的控制器听UIApplicationDidBecomeActiveNotification通知。

+0

你能告诉我一个如何在我的视图控制器中使用UIApplicationDidBecomeActiveNotification的例子吗? – 2010-07-21 15:37:35

0

您可以创建名为TableViewManager的班级。在那里注册列表UITableView,以便您可以刷新任何你想要的表。 是这样的,在你的TableViewManager类中,有一个名为

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