1

每当用户重新进入我的 iphone 应用程序时,我一直在尝试重新加载表格。表格的所有信息都是正确和正确的。该表正在输入正确的数据源和委托,并且我打印出来的值是我想要的,但从视觉上看,表不会重新加载。我的调用在 appWillEnterForeground 中,调用 viewWillLoad。

4

2 回答 2

7

您不应该像上面评论中描述的那样触发 viewDidLoad 。viewDidLoad 是 CocoaTouch 框架在适当的时候调用的特殊方法。您的代码不应直接调用它。

相反,您可以使用通知来完成同样的事情。这是执行您要求的正确方法:

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Fire a notification to let all views know that our app entered foreground.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"EnteredForeground" 
                                                        object:nil];
}

在您的特定 ViewController 中处理通知:

- (void)viewDidLoad {
    ...
    [NSNotificationCenter defaultCenter] addObserver:self 
                                            selector:@selector(enteredForeground:) 
                                                name:@"EnteredForeground" 
                                              object:nil];
}

// Handle the notification in your ViewController:

- (void)enteredForeground:(id)object {
    // Reload the tableview
    [self.tableView reloadData];
}
于 2012-06-06T16:36:40.797 回答
2

您可以只观察 UIApplicationWillEnterForegroundNotification 而不是发布自己的通知:

[[NSNotificationCenter defaultCenter] addObserver:self.tableView selector:@selector(reloadData) name:UIApplicationWillEnterForegroundNotification object:nil];
于 2014-04-08T20:16:17.800 回答