TTThumbsViewController 滚动时显示图像
我正在扩展 TTThumbsViewController 来显示来自外部源的照片。一切正常,但我想更改控制器的一种行为:我想在用户仍在滚动时而不是仅在用户完成滚动时在 TTThumbsViewController 中显示/加载图像。
我在 TTTableViewDelegate.m 中看到,滚动开始时请求被挂起,我尝试将其设置为“否”,但它似乎只获取图像,而在完成加载时并未实际显示它们。
//TTTableViewDelegate.m
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[TTURLRequestQueue mainQueue].suspended = YES;
...
}
此外,我连接了开始和结束拖动委托调用,尝试每秒左右刷新视图,希望显示缩略图,我尝试过调用 invalidateView
、reload
以及主线程上的更多内容,但似乎都不起作用(invalidateModel
不适合我的目的)。
有人能指出我正确的方向吗?
预先感谢
Edit1:如果我在使用 [TTURLRequestQueue mainQueue].suspended = NO;
时滚动,状态栏中会有一个加载程序,但它实际上并没有获取图像,用wireshark确认。
Edit2:经过更多调试后,我发现请求是以编程方式发送的,但只有在完成滚动后才会收到响应,因此看来 NSURLConnection
的异步委托方法是在滚动 scrollView
时不会触发,但我已经设法在另一个具有 tableView 的视图控制器中执行类似的代码(工作),而无需使用 Three20 lib。
I'm extending TTThumbsViewController
to display photos from external source. Everything works fine but I'd like to change one behaviour of the controller: I'd like to display/load images in TTThumbsViewController
while the user is still scrolling and not only when the user finishes scrolling.
I saw that in TTTableViewDelegate.m
the requests are being suspended when scrolling starts and I've tried setting it no NO but it only seems to fetch the images and not actually displaying them when they finish loading.
//TTTableViewDelegate.m
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[TTURLRequestQueue mainQueue].suspended = YES;
...
}
In addition I hooked to the begin and end dragging delegate calls to try and refresh the view every second or so with hopes of displaying the thumbnails, I've tried calling invalidateView
, reload
and a couple more on the main thread but none seemed to work (invalidateModel
doesn't suit my purposes here).
Could anyone point me in the right direction?
Thanks in advance
Edit1: there is a loader in status bar if I scroll when I use [TTURLRequestQueue mainQueue].suspended = NO;
but it doesn't actually fetch the images, confirmed with wireshark.
Edit2: after a bit more debugging I found that the request is sent programatically but the response is only received after we finish scrolling, so it seems the asynchronous delegate methods of NSURLConnection
are not firing while a scrollView
is being scrolled, but I've managed to do similar code (working) in another view controller with a tableView without using three20 lib.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在谷歌搜索大量线程和论坛后,我终于实现了我想要的行为,尽管我更改了 Three20 代码而不是在一部分中扩展它:在我的thumbsViewController中我实现了以下委托,允许在滚动时发出请求:
现在为了解决滚动时未处理连接的问题,我发现当 UIScrollView 滚动时 NSURLRequest 不会触发 有用并且在 TTRequestLoader.m 我更改了以下内容:
After googling around numerous threads and forums I finally achieved the behaviour I wanted, although I changed three20 code instead of extending it in one part: in my
thumbsViewController
I implemented the following delegate allowing requests to be made while scrolling:Now to solve the problem of the connections not being processed while scrolling I found NSURLRequest won't fire while UIScrollView is scrolling useful and in TTRequestLoader.m I changed the following: