2010-07-21 22 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]; } 
相關問題