2

我正在扩展TTThumbsViewController以显示来自外部来源的照片。一切正常,但我想更改控制器的一种行为:我想TTThumbsViewController在用户仍在滚动时显示/加载图像,而不仅仅是在用户完成滚动时。

我看到在TTTableViewDelegate.m滚动开始时请求被暂停,我尝试将其设置为否,但它似乎只是获取图像而不是在它们完成加载时实际显示它们。

//TTTableViewDelegate.m
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  [TTURLRequestQueue mainQueue].suspended = YES;
  ...
}

此外,我连接到开始和结束拖动委托调用以尝试每秒左右刷新一次视图,希望显示缩略图,我尝试调用invalidateViewreload并且在主线程上还有几个,但似乎没有一个工作(invalidateModel不不适合我的目的)。

谁能指出我正确的方向?

提前致谢

Edit1:如果我在使用时滚动,状态栏中会有一个加载器,[TTURLRequestQueue mainQueue].suspended = NO;但它实际上并没有获取图像,用wireshark确认。

Edit2:经过更多调试后,我发现请求是以编程方式发送的,但仅在我们完成滚动后才收到响应,因此在滚动NSURLConnectiona 时似乎没有触发异步委托方法scrollView,但我设法做到了在另一个视图控制器中使用 tableView 的类似代码(工作)而不使用three20 lib。

4

1 回答 1

0

在谷歌搜索了许多线程和论坛之后,我终于实现了我想要的行为,尽管我更改了 three20 代码而不是在一个部分中扩展它:在我的实现中,thumbsViewController我实现了以下委托,允许在滚动时发出请求:

-(void)didBeginDragging {
    [super didBeginDragging];
    [TTURLRequestQueue mainQueue].suspended = NO;
}

现在要解决滚动时连接未处理的问题,我发现NSURLRequest 在 UIScrollView 滚动有用时不会触发,并且在 TTRequestLoader.m 中我更改了以下内容:

//TTRequestLoader.m
- (void)connectToURL:(NSURL*)URL {
    ...
    //To allow requests while scrolling we must schedule the conenction in other run loop
    //_connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self];
    //code above was replaced by the one below
    _connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self startImmediately:NO];
    [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    [_connection start];
}
于 2011-12-15T16:59:20.307 回答