如何使用NotificationCenter UIApplicationDidBecomeActiveNotification 重新加载我的RSS Feed
我创建了一个从服务器上的 XML feed 文件加载数据的应用程序。这工作正常,但我希望它在按下主页按钮时刷新。我知道我需要使用 UIApplicationDidBecomeActiveNotfication notif 但我似乎无法让它重新加载提要。任何帮助将不胜感激。
I've created a app that loads data from a XML feed file on my server. This works fine but I want it to refresh if the home button is pressed. I know that I need to use the UIApplicationDidBecomeActiveNotfication notif but I can't seem to get it to reload the feed. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在具有重新加载方法的类中,您需要在初始化期间(或您想要开始观察的任何地方)添加一个观察者来观察通知,如下所示。您可以设置一个执行重新加载的选择器,我在这里使用了 reloadXMLData,但您可以将其更改为任何内容。
如果您在初始化期间添加观察者,请务必在您的类被释放后将其删除。如果您将其添加到其他地方,则需要将其删除,否则如果您的类被释放并且观察者仍然处于活动状态,您的应用程序将崩溃
现在,每次触发 UIApplicationDidBecomeActiveNotification 时,只要您的类存在,就会调用 reloadXMLData 方法是活跃的。
In the class which has the Reloading Methods, you need to add an Observer during init (or wherever you want to start observing) to observe for the notification like shown below. You can set a selector which does the reloading, i've used reloadXMLData here but you can change that to whatever.
Also be sure to remove the Observer once your Class is dealloced if you add it during init. If you add it somewhere else, you'll need to remove it otherwise if your class is dealloced and the observer is still active, your app will crash
Now every time the UIApplicationDidBecomeActiveNotification is fired, the reloadXMLData method will be called as long as your class is active.