从AppDelegate重新加载tableView [英] Reload a tableView from the AppDelegate

查看:128
本文介绍了从AppDelegate重新加载tableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很简单的问题,但我仍然在找可可。
我有一个正常的rootViewController应用程序在Xcode中创建。在AppDelegate中,我有一个函数来更新数据库。当一个push消息运行时(didReceiveRemoteNotification :)的数据被更新。

I have a pretty simple question, but am still finding my way around cocoa. I have a normal rootViewController App as created in Xcode. In the AppDelegate I have a function to update the database. When a Push-message comes in while running (didReceiveRemoteNotification:) the data is updated.

但是如何获得一个句柄的RootViewController告诉它更新其对象然后重新加载表(这是一个函数)?

But how do I get a handle on the the RootViewController telling it to update its objects and then reload the table (which is a function)?

推荐答案

可以使用 NSNotificationCenter ,请参阅 NSNotificationCenter类参考 a>

You can use NSNotificationCenter, see NSNotificationCenter Class Reference

rootViewController viewDidLoad 添加以下内容:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"updateRoot" object:nil];

并添加以下方法:

- (void)updateView:(NSNotification *)notification {
    [myTableView reloadData]; 
}

AppDelegate didReceiveRemoteNotification ,添加以下内容:

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil];

这篇关于从AppDelegate重新加载tableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆