gpt4 book ai didi

objective-c - IOS:来自 Json 的 LazyLoad 图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:03 24 4
gpt4 key购买 nike

我是这种编程语言的新手...我尝试从某些服务器使用 json,在成功使用所有信息后,现在我遇到了将“延迟加载”图像显示到 tableviewcell 中的问题

我用 AsyncImageView实现它,这是我的代码

-(UITableViewCell *)tableView :(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NetraCell *cell =(NetraCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil){
cell=[[NetraCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

//common settings
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
cell.imageView.clipsToBounds = YES;

///get url image from url
//NSString *path=[[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"image"]objectForKey:@"thumbnail"];

////convert image into NSDATA
// NSData* imageData = [NSData dataWithContentsOfURL: [NSURL URLWithString: path]];
////read NSData Image
// UIImage* image = [UIImage imageWithData: imageData];
//////set rounded imager with NetraImage

// image=[ImageManipulator makeRoundCornerImage:image : 30 : 30];

////show image into UItableviewCell
// cell.imageView.image=image;

}
else{
//cancel loading previous image for cell
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.imageView];
}
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
cell.imageView.imageURL = [[[imageURLs objectAtIndex:indexPath.row]objectForKey:@"image"]objectForKey:@"thumbnail"];

NSString *price=[[[somearray objectAtIndex:indexPath.row] objectForKey:@"price"]objectForKey:@"formatted"];
///call image from JSOn


///draw to tableviewcell
if(price!=NULL){
cell.detailTextLabel.text= [[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"price"]objectForKey:@"formatted"]; //1 draw the price
//[cell release]
}
else{
cell.detailTextLabel.text= @"Call";

}
//draw headline
cell.textLabel.text=[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"headline"];
///draw image


[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
return cell;
}

这条线是我的图片路径

//NSString *path=[[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"image"]objectForKey:@"thumbnail"];

这是将图片分配给 uitableviewcell 的默认方法

cell.imageView.imageURL = [imageURLs objectAtIndex:indexPath.row];

但是当我尝试这个方法的时候

cell.imageView.imageURL = [[[imageURLs objectAtIndex:indexPath.row]objectForKey:@"image"]objectForKey:@"thumbnail"];

它的错误,主要问题是

  1. 为什么会出错?是我的远程图像路径错了吗?或者我的方法不对

需要你的帮助:) 非常感谢

最佳答案

一旦检查您是否在代码中为单元格图像 url 分配了适当的 imageurl,[[[imageURLs objectAtIndex:indexPath.row]objectForKey:@"image"]objectForKey:@"thumbnail"],然后通过这个,它可能对你有帮助 lazy loading of images in UITableView cell

关于objective-c - IOS:来自 Json 的 LazyLoad 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12831770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com