【发布时间】:2011-04-29 07:33:54
【问题描述】:
我正在UITableView 中实现异步图像加载,如果我快速滚动行,我的应用程序由于发送给僵尸的消息而崩溃...我在这里做错了什么?
//loading image from URL
-(void)loadImageFromURL:(NSURL*)url {
if (connection!=nil) { [connection release]; }
//data is NSMutableData
if (data!=nil) { [data release]; }
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
//Append received data when it is received
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) { data = [[NSMutableData alloc] init]; }
[data appendData:incrementalData]; //Message sent to zombie, app CRASHES HERE
}
//When finished
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
//so self data now has the complete image
[connection release];
connection=nil;
//Use received data to construct image
[data release];
data=nil;
}
【问题讨论】:
-
由于您的应用在滚动时崩溃,因此查看
tableView:cellForRowAtIndexPath:中发生的代码可能会有所帮助 -
“数据”是 NSData 还是 NSMutableData?
-
我还以为是吸血鬼杀死了应用程序
-
@Mark 我怪我女朋友和暮光闪闪,如果我再听到吸血鬼的话我会呕吐
标签: iphone objective-c memory ios4