EGOImageLoading在UITableView滚动时无法加载图片do not load while scrolling
2013-11-17 03:25
393 查看
场景:每个cell中有一个EGOImageView
问题的现象:在滚动时,无法加载图片;滚动一停止,很快就加载成功。
原理:主线程中一个NSTimer添加在default mode中,当界面上有一些scroll view的滚动频繁发生导致run loop运行在UItraking mode中,从而这个timer没能如期望那般的运行。所以,我们就可以把这个timer加到NSRunLoopCommonModes中来解决(iOS中)。
解决方法:来源
EGOImageLoader/EGOImageLoadConnection.m
line57
- _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
+ _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
+ [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
+ [_connection start];
EGOImageLoader/EGOImageLoader.m
line136
- [connection performSelector:@selector(start) withObject:nil afterDelay:0.01];
+ [connection performSelector:@selector(start) withObject:nil afterDelay:0.01 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
这两篇文章分析了原理:
NSTimer 被UIScrollView block住的處理
NSRunLoop的一点理解
问题的现象:在滚动时,无法加载图片;滚动一停止,很快就加载成功。
原理:主线程中一个NSTimer添加在default mode中,当界面上有一些scroll view的滚动频繁发生导致run loop运行在UItraking mode中,从而这个timer没能如期望那般的运行。所以,我们就可以把这个timer加到NSRunLoopCommonModes中来解决(iOS中)。
解决方法:来源
EGOImageLoader/EGOImageLoadConnection.m
line57
- _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
+ _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
+ [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
+ [_connection start];
EGOImageLoader/EGOImageLoader.m
line136
- [connection performSelector:@selector(start) withObject:nil afterDelay:0.01];
+ [connection performSelector:@selector(start) withObject:nil afterDelay:0.01 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
这两篇文章分析了原理:
NSTimer 被UIScrollView block住的處理
NSRunLoop的一点理解
相关文章推荐
- SDWebImage在UITableView部分CELL图片无法加载的解决办法
- EGOImageView 滚动无法加在图片
- iOS学习笔记47——图片异步加载之EGOImageLoading
- 异步加载图片的公用类: EGOImageLoading
- IOS学习之路二十三(EGOImageLoading异步加载图片开源框架使用)
- 解决UITableView中image加载不同宽度尺寸图片的问题
- 一个异步加载图片的公用类: EGOImageLoading
- 网络图片加载的第三方类:EGOImageView的使用方法及注意事项
- IOS学习之路二十三(EGOImageLoading异步加载图片开源框架使用)
- 解决UITableView中image加载不同宽度尺寸图片的问题
- 开源中国iOS客户端学习——(十四)使用EGOImageLoading异步加载图片
- 一个异步加载图片的公用类: EGOImageLoading
- 开源中国iOS客户端学习——(十四)使用EGOImageLoading异步加载图片
- 一个异步加载图片的公用类: EGOImageLoading
- 开源中国iOS客户端学习——(十四)使用EGOImageLoading异步加载图片
- 开源中国iOS客户端学习——(十四)使用EGOImageLoading异步加载图片
- [置顶] iOS学习笔记47——图片异步加载之EGOImageLoading
- iOS开发之EGOImageLoading异步加载图片公用类
- RoundedImageView使用吐槽心得(RoundedImageView与Glide加载图片,第一次加载无法圆角问题)
- EGOImageLoading 异步加载图片带缓存