29,027
社区成员
发帖
与我相关
我的任务
分享
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * CellFlg = @"cell";
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:CellFlg];
if (cell==nil) {
cell = [[[ UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellFlg] autorelease];
}
NSString * cellValue = [[nearData objectAtIndex:indexPath.row] objectForKey:@"title"];
cell.textLabel.text = cellValue;
//这里每当屏幕滚动,重新执行的时候 就在这里崩溃了
NSArray *imgArr = [imageData objectForKey:indexPath];
if (imgArr==nil){
[self startDownLoadImage :indexPath.row forIndexPath:indexPath];
//单元格图标
UIImage *image = [UIImage imageNamed:@"apple.jpeg"];
cell.imageView.image = image;
return cell;
}
return cell;
}
-(void) startDownLoadImage:(NSInteger)index forIndexPath:(NSIndexPath *) indexPath{
//使用ASIHttpRequest的异步下载
NSMutableDictionary *test = nearData;
NSString *imgUrl = [[[test objectAtIndex:index] objectForKey:@"user"] objectForKey:@"picture"];
NSArray *imgArr = [NSArray arrayWithObjects:imgUrl,nil];
//此处对 imageData 赋值
[imageData setObject:imgArr forKey:indexPath];
[t_imageData setObject:imgArr forKey:indexPath];
NSURL *url = [NSURL URLWithString:imgUrl];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
request.indexPathInTableView = indexPath;
[request setDownloadDestinationPath:[[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"3.jpg"]];
[request startAsynchronous];
//[imgArr release];
//显示等待图标
//[m_pIndicator startAnimating];
}