从应用程序的线程中触发多个视图控件的

从应用程序的线程中触发多个视图控件的

本文介绍了从应用程序的线程中触发多个视图控件的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSAutoreleasePool线程,旨在从Web服务中提取信息,我的Web服务代码工作得很好,我可以触发线程启动在视图控制器没有任何麻烦,实际上它的工作相当不错



我想:




  • 将线程实例化移动到appDelegate - 容易!

  • 让它定期运行,并以某种方式告诉它下面的viewcontrollers(5 - 10)如果下载了新的信息

  • 有手动的能力执行调度程序之外的线程



我可以使用performSelectorOnMainThread启动appdelegate上的方法,但是如何可以让我的子视图控制器要订阅一个方法的appdelegate?

解决方案

使用NSNotificationCenter你可以发布,通知:D
这样没有appDelegate现在其他类可以订阅到其他类他的通知他们需要。



另外,我会保持线程活着,每次产生一个新的线程是昂贵的,只有经常生成它。我建议使用GCD(iOS 4+)


I have an NSAutoreleasePool thread that is designed to pull information down from a web service, i have the web service code working nicely and i can trigger the thread to start in a view controller without any trouble, in fact its working quite nicely.

I want to:

  • move the thread instantiation to the appDelegate - easy!
  • have it run periodically and somehow tell the viewcontrollers under it (5 - 10) if new information is downloaded
  • have the capacity to manually execute the thread outside of the scheduler

I can fire up a method on the appdelegate using performSelectorOnMainThread but how i can get my child view controllers to "subscribe" to a method on the appdelegate?

解决方案

Using NSNotificationCenter you can post well, notifications :DThat way without the appDelegate nowing the other classes the other classes can "subscribe" to the notifications they need.

Also, i would keep the thread alive, spawning a new thread everytime is costly, ofc only if it is spawned often. I would recommend using GCD ( iOS 4+ )

这篇关于从应用程序的线程中触发多个视图控件的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:39