第二次尝试如何理解运行循环
可能的重复:
runloop 的实际工作原理
嗨,
我之前问过这两个问题,但我确实这样做了不明白。
有关 Runloop 的问题 1
关于 Runloops 2 的问题
在我的一本 iPhone 书中,他们提到了 run循环如下:
“你的应用程序是一个巨人 无限循环称为运行循环。这 runloop的工作是检查输入 (触摸、核心位置更新、数据 通过网络接口, 等)并找到合适的 该事件的处理程序(例如 的操作或委托方法 对象)。”
好的,那么循环到底在哪里?我知道主应用程序线程不需要运行它,并且每个线程都有一个关联的运行循环对象,但是它的实际循环部分在哪里?它是否是一个不可见的 while 循环围绕着主方法,如果它是一个正在循环的循环,那么它不会循环我的所有代码。我知道这是错误的,但并没有这样做。
我不理解运行循环可以运行的不同模式,但也许是因为我不理解运行循环。
提前致谢!
Possible Duplicate:
How a runloop actually works
Hi
I have asked these two questions earlier, but yet I do not understand it.
Question about Runloops 1
Question about Runloops 2
In one of my iPhone-books they mention the run loop as this:
”Your application is one giant
infinite loop called the run loop. The
run loop’s job is to check for input
(a touch, Core Location updates, data
coming through a network interface,
etc.) and find the appropriate
handlers for that event (like an
action or delegate method for an
object).”
Okey, so where exactly is the loop? I know that the main application thread don’t need to run it and every thread has an associated run loop object however where is the actual loop portion of it? Is it a while loop that invisible surrounds the main-method, and if it where a loop that was looping wouldn’t that loop all of my code. I understand that this is wrong and it is not done though.
I do not understand the different modes a runloop can run in either, but maybe it is because I do not understand the runloop.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 iPhone(或任何 Cocoa,但 Cocoa 正确使用 NSApplicationMain 而不是 UIApplicationMain)应用程序的典型“main()”函数:
这是整个应用程序,没有任何异常或“包裹”这个 main()常规。因此,从逻辑上讲,您可以得出结论,运行循环包含在对 UIApplicationMain 的调用中。
Take a look at the typical "main()" function for an iPhone (or any Cocoa, but Cocoa proper uses NSApplicationMain instead of UIApplicationMain) application:
This is the entire application, there is nothing unusual or "wrapped around" this main() routine. So, logically, you can conclude that the run loop is contained within the call to UIApplicationMain.