【发布时间】:2012-03-06 17:58:47
【问题描述】:
我在 UIScrollView 中有 UIImageView。 UIImageView 显示不断从互联网下载的图像(使用 NSURLConnection 打开的流)。
NSString surl = @"some valid url";
NSURL* nsurl = [NSURL URLWithString:surl];
NSURLRequest *request = [NSURLRequest requestWithURL:nsurl];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
// this method will be called when every chunk of data is received
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// here I collect data and when i have enough
// data to create UIImage i create one
}
每次我收到数据时,我都会将它打包到一个 NSData 中,当我收到整个图像时,我会从这个 NSData 创建 UIImage,然后我将此图像设置为 UIImageView 的图像。一切正常,图像更新正常,但是当我触摸屏幕并开始移动内容时(这个 UIImageView 总是比屏幕大,UIScrollView 总是适合整个屏幕)图像更新停止,我只看到最后一帧显示在我点击的时间。这似乎是因为我的
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
停止被调用。从屏幕方法释放我的手指后,再次接收数据和图像更新。我不知道为什么我的 NSURLConnection 委托方法停止接收数据。有什么帮助吗?
【问题讨论】:
标签: iphone uiscrollview uiimageview freeze nsurlrequest