- 浏览: 239523 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (118)
- Ruby/ROR (4)
- Mac (28)
- 我的见闻触发你我的灵感 (1)
- 创业 (1)
- JOSSO (2)
- XML (2)
- OpenRemote (1)
- 娱乐 (2)
- 版权/License (1)
- Java/Spring (4)
- 调试 (1)
- 路由器 (2)
- 技术博客 (21)
- 虚拟机 (1)
- Javascript (6)
- SVN (2)
- HA(Home Automation) (0)
- Android (2)
- iPhone/iPod (23)
- iPad (22)
- iOS公共 (28)
- Windows7 (1)
- 服务器技术 (2)
- 其它 (1)
- Shell (1)
- 数据库 (1)
- 问题总结 (1)
最新评论
-
zjjzmw1:
...
转载:IOS开发之——objectForKey与valueForKey在NSDictionary中的差异 -
hldfxh:
解决了我的问题
JSON Lib, XML转JSON字符串不要namespace,以及处理特殊xml属性"type" -
herry68:
可以给我提供以下你的这个NSData+Base64.h类吗
图片转base64串及反转回图片 -
herry68:
我用这个方法把图片转换成nsstring成功了,但是从nsst ...
图片转base64串及反转回图片 -
hibluse:
handy.wang 写道hibluse 写道我已经设置了WA ...
基于FMDB-SQLite的App数据库性能优化
A run loop is a mechanism that provides the possibility for the system to wake up sleeping threads to manage asynchronous events. Normally when you run a thread (with the exception of the main thread) you have the option to start for it a run loop or not. If the thread does some sort or long-runnign operation with no interaction with external events and no timers, you don't need a run loop, but if your thread needs to respond to incoming events, you need to attach it to a run loop in order to wake up this thread when new events arrive. This is the case of NSURLConnection generated threads, as the live on incoming events only (from the network).
Each thread can be associated to different run loops, or it can be associated to a run loop but this run loop can be set to work on different modes. A "run loop mode" is a convention used by the OS to establish some rules on when delivering certain events or simply suspend this delivery and then collect them all to be delivered later. Usually all run loop are set to the "default mode" which establishes a default way to manage input events. As soon as some mouse-dragging (Mac OS) or touch (on iOS) event happens then the mode for this run loop is set to event tracking: this means that the thread will not be woke up on new network events but these events will be delivered later when the user input event terminates and the run loop set to default mode again: obviously this is a choice made by the OS architects to give priority to user events instead of background events.
If you decide to change the run loop mode for your NSURLConnection thread, by using the
scheduleInRunLoop:forModes:
method, then you allow the thread's events to be associated not to a specific run loop (the default) but to a different run loop mode. In particular the special pseudo-mode called "common" allows to permanently associate the input sources to all modes that are - or will be - associated to the "common mode". Of course event tracking mode is part of this family of modes, so the method applied on NSURLConnection's instance means: please associate the connection source events to "tracking mode" in addition to "default mode".
Finally you can add new modes to the common modes, but this is a quite low-level operation.
I would to close by adding a few notes: - typically we need to associate to a table view a set of images or thumbnails downloaded from the network; even if we may thing that download these images from the network while the table view is scrolling could improve the UI (because we can see the images while scrolling) infact this is dangerous as the final effect will be a scrolling not fluid. So don't add NSURLConnection to the run loop in such case but use the UIScrollView delegate methods to detect when scrolling is terminated to update the table and download new items from the network - you may consider to use GCD which will help you to "shield" your code from run loop management issues. So in the example above, you may consider to add your network requests to a custom serial queue.
from: http://stackoverflow.com/questions/7222449/nsdefaultrunloopmode-vs-nsrunloopcommonmodes
发表评论
-
图片转base64串及反转回图片
2013-07-29 12:04 2323图片转base64串: UIImage *_ori ... -
iOS中异步函数的单元测试
2013-06-08 09:51 1507转载自:http://blog.csdn.net/diyag ... -
拆数算法(ObjectiveC递归实现)
2013-03-21 10:45 2070把一个大数拆成几个指定的小数相加,以下实现方式性能很差仅供参考 ... -
[iPhone高级] 基于XMPP的IOS聊天客户端程序(IOS端一)
2012-12-16 15:56 8612转载自:http://blog.csdn.net/kangka ... -
复杂数据类型变量的引用计数与block以及__block修饰符的关系
2012-12-14 17:05 4883以下结论是结合参考资料和实验得来,不对地方请大家纠正: ... -
基于FMDB-SQLite的App数据库性能优化
2012-12-14 16:48 111731)如果数据库配置成为串行模式:sqlite3_con ... -
Run Loop
2012-08-24 11:12 1247来源:http://www.cnblogs.com/scorp ... -
转载:IOS开发之——objectForKey与valueForKey在NSDictionary中的差异
2012-08-23 15:49 1326来源:http://blog.csdn.net/pjk1 ... -
深拷贝和浅拷贝
2012-08-23 15:44 954来源:http://blog.csdn.net/pjk1129 ... -
静态全局变量的内存问题
2012-08-23 15:43 1168来源:http://blog.csdn.net/pjk1 ... -
如何将iPhone模拟器的分辨率调整至1136x640?
2012-08-09 10:01 3131来源:http://www.weiphone ... -
AtoS查看iOS Crash log中的16进制代码日志
2012-08-02 17:21 3413注意:crash_log一定要和打包时的archive对应上; ... -
Objective-c 中 nil, Nil, NULL和NSNull的区别
2012-08-02 10:40 946来自:http://blog.csdn.net/yhawaii ... -
XCODE4.3.2与真机联调时,console里输出中文乱码
2012-07-19 13:34 1313修改项目的scheme的info,把debugger由LLDB ... -
NSAutoReleasePool使用中drain和release的区别
2012-05-30 14:50 1692虽然ARC引入之后NSAutoReleasePool的使 ... -
Network Link Conditioner in Lion
2012-05-21 14:46 1909Network Link Conditioner in ... -
PushMeBaby中的神秘错误代码OSStatus的实际含义
2012-05-03 09:31 76201)查看SecureTransport.h中 / ... -
NSParameterAssert
2012-04-20 09:38 2646NSParameterAssert Valida ... -
线程内sleep
2012-04-19 09:20 1060[NSThread sleepForTim ... -
转换Xcode里打印的unicode编码日志
2012-04-18 20:33 18021)打开Terminal 2)输入python 3)pri ...
相关推荐
NSRunLoop的模式:NSRunLoop有多个运行模式(如NSDefaultRunLoopMode、NSRunLoopCommonModes等),不同的模式下,处理事件的方式有所不同。 2. **Run Loop管理** - A. Run Loop的创建与操作:你可以通过`+...
`RunLoop`有多个模式,常见的有`NSDefaultRunLoopMode`和`NSRunLoopCommonModes`。选择正确的模式很重要,否则可能导致定时器无法正常触发。 五、`NSTimer`的线程问题 由于`NSTimer`非线程安全,通常在主线程中创建...
[[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSDefaultRunLoopMode]; 改为: /*每秒刷新60次的定时器*/ _time = [CADisplayLink displayLinkWithTarget:self selector:@selector(play)]; /*将...
- RunLoop的模式也很重要,如`NSDefaultRunLoopMode`和`NSRunLoopCommonModes`,不同的模式可能会影响`NSTimer`的触发。 6. **NSTimer的重复与精确性**: - `repeats`参数决定了`NSTimer`是否在首次触发后重复...
需要注意的是,`NSTimer` 默认运行在 `NSDefaultRunLoopMode` 模式下,该模式包含大多数输入源,但不包括`UITableView`或`UIScrollView`的滑动事件。因此,当你在主界面上滑动`UITableView`或`UIScrollView`时,由于...
> forMode:NSDefaultRunLoopMode]; > > NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; > [parameters setObject:mainPort forKey:@"port"]; > > // start the secondary threads > // loop ...
NSDefaultRunLoopMode用于常规运行,而UITrackingRunLoopMode是在用户与界面交互时使用的,保证滚动等操作的平滑进行。 在实际开发中,开发者可能需要自定义Run Loop的行为,例如添加自定义事件源、定时器或者在...
`NSRunLoopCommonModes`实际上等同于`NSDefaultRunLoopMode`加上`UITrackingRunLoopMode`。 4. **UIInitializationRunLoopMode**:应用程序启动时进入的第一个模式。启动完成后不再使用。 5. **...
SwiftyTimer 是一组扩展,可以使 NSTimer API 更加清晰易用,亲近 Swift 语法。使用示例:使用 NSTimer.every ...timer.start(modes: NSDefaultRunLoopMode, NSEventTrackingRunLoopMode) 标签:SwiftyTimer
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [inputStream open]; ...
如果在NSDefaultRunLoopMode下运行计时器,则计算运行NSDefaultRunLoopMode 。 iPhone 5S 得出的结论约为4375次/秒。 当计时器时间间隔朝100ms范围减小时,我们达到了渐近极限,这一点很明显。 仿真器 得出的结论约...
- 考虑RunLoop模式:理解NSRunLoop的不同模式,如NSDefaultRunLoopMode和UITrackingRunLoopMode,确保计时器在正确的情景下触发。 - 优化性能:例如,对于CADisplayLink,可能探讨了如何调整其frameInterval属性来...
`NSRunLoop`可以通过设置模式(如`NSDefaultRunLoopMode`或`UITrackingRunLoopMode`)来控制其行为。不同的模式决定哪些源会在特定时间被处理。例如,在视图滚动时,`UIKIT_DURING_VIEW_SCROLL`模式可以防止定时器...
3. 实现基于GCD的异步任务,并在任务完成后通过`NSRunLoop`的模式(如`NSDefaultRunLoopMode`)发送通知,演示`NSRunLoop`与GCD的协作。 4. 演示如何在`NSRunLoop`中监听网络请求或其他I/O操作的完成,以便在数据...
iOS 中的定时器使用教程 ...[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; ``` 本文详细介绍了 iOS 中最全的各种定时器的使用教程,使得开发者们更好地理解和使用定时器。
Runloop的工作模式分为两种:kCFRunLoopDefaultMode(通常称为NSDefaultRunLoopMode)和UITrackingRunLoopMode。前者是主线程的默认模式,用于处理大部分的日常任务;后者在用户滚动视图时激活,以提供更流畅的用户...
4. 模式(Modes):Run Loop有多种模式,如NSDefaultRunLoopMode、UITrackingRunLoopMode等,不同模式下处理不同的事件。 5. 休眠与唤醒:当没有事件处理时,Run Loop会让应用进入休眠状态,一旦有新的事件到达,就...
- 必须将NSTimer添加到RunLoop中,通常会自动加入到MainRunLoop的`NSDefaultRunLoopMode`。 然后,我们来看**CADisplayLink**,它是iOS中一种更为精准的定时器,主要用于与屏幕刷新同步的任务,常用于动画和界面...
2. **利用RunLoop**:通过`[NSRunLoop currentRunLoop]`获取当前RunLoop,并在`NSDefaultRunLoopMode`模式下添加一个定时器。定时器会在RunLoop的下一个循环中触发,即在用户停止滚动后。 3. **设置定时器**:创建...
2. **Run Loop的模式**:Run Loop有两种主要运行模式:`NSDefaultRunLoopMode`(默认模式)和`UITrackingRunLoopMode`(用于滑动等连续用户交互)。在不同模式下,Run Loop会处理不同的事件源和定时器。 3. **Run ...