我解析一个xml文件,其中包含拇指图像的网址。我想在一个可用视图中显示这些大拇指。在tableview中加载异步图像,他们在每一次滚动消失
使用class AsyncImageView(在this website上找到),我的代码工作。
唯一的问题是:每当用户滚动uitableview,图像消失片刻...然后重新出现(我认为我每次下载图像,但我不知道)!
这是一个丑陋的效果,我希望如果图像下载,它保持可见。
这是我的代码(注意:在array_thumb有网址前解析):在你的代码或AsyncImageView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier;
static NSString *NibNamed;
UIDeviceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (deviceOrientation != UIDeviceOrientationLandscapeLeft &&
deviceOrientation != UIDeviceOrientationLandscapeRight)
{
CellIdentifier= @"Cell1";
NibNamed = @"cell_gallery";
}
else
{
CellIdentifier= @"Cell2";
NibNamed = @"cell_gallery_landscape";
}
[[NSBundle mainBundle] loadNibNamed:NibNamed owner:self options:NULL];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:NibNamed owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else {
AsyncImageView* oldImage = (AsyncImageView*)[cell.contentView viewWithTag:1];
[oldImage removeFromSuperview];
}
CGRect frame;
frame.size.width=72; frame.size.height=72;
frame.origin.x=10; frame.origin.y=10;
AsyncImageView* asyncImage = [[[AsyncImageView alloc] initWithFrame:frame] autorelease];
NSString *title = [NSString stringWithFormat:@"%@", [array_title objectAtIndex:indexPath.row]];
UILabel *testoLabel = (UILabel*)[cell viewWithTag:2];
testoLabel.text = title;
asyncImage.tag = 1;
NSLog(@"%@", asyncImage);
NSURL *url = [NSURL URLWithString:[array_thumb objectAtIndex:indexPath.row]];
asyncImage.layer.cornerRadius = 10.0;
asyncImage.layer.masksToBounds = YES;
[asyncImage loadImageFromURL:url];
[cell.contentView addSubview:asyncImage];
UIColor *miocolore1 = [[UIColor alloc] initWithRed:247.0/255 green:247.0/255 blue:247.0/255 alpha:1.0];
UIColor *miocolore2 = [[UIColor alloc] initWithRed:233.0/255 green:233.0/255 blue:233.0/255 alpha:1.0];
if (indexPath.row % 2 == 0) {
cell.contentView.backgroundColor = miocolore1;
}
else {
cell.contentView.backgroundColor = miocolore2;
}
return cell;
}
ASIHTTPRequest的最后一个版本是在撰写本文时的三年前。查看[AFNetworking](https://github.com/AFNetworking/AFNetworking)。 – 2014-01-10 22:54:34