gpt4 book ai didi

ios - 当我使用 SDWebImage 时滚动不正确

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:50 25 4
gpt4 key购买 nike

我在滚动表格时遇到了这个非常严重的问题。

最初我使用 GCD 在背景中加载图像并在表格单元格上设置。但 table 滚动不顺畅。所以我为此使用了 SDWebImage,但随后发生了同样的事情。

谁能告诉我这是什么原因。为什么 table Scrolling 没有预期的那么流畅。

请让我知道您的意见,因为我的应用正在等待其发布的唯一目的是相同的。

代码:

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

NSString *CellIdentifier = @"Cell";
customCellForExhibitor *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
NSArray *xibPath = [[NSBundle mainBundle]loadNibNamed:@"customCellForExhibitor" owner:self options:nil];
for (id fileObject in xibPath)
{
cell = (customCellForExhibitor*)fileObject;
}
}

objDataModel = [parserDataContentArray objectAtIndex:indexPath.section];

cell.exhibitorNameLabel.text = [objDataModel exhibitorNameObjectClass];
cell.exhibitorText.text = [objDataModel exhibitorOfferObjectClass];
cell.exhibitorSponsorType.text = [objDataModel exhibitorSponsorTypeObjectClass];

[cell.exhibitorSponsorType setTextAlignment:NSTextAlignmentRight];



// #pragma mark GCD;
//
// NSString *ImageURL = [[parserDataContentArray objectAtIndex:indexPath.section] exhibitorImageObjectClass];
//// NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
//// cell.exhibitorImage.image = [UIImage imageWithData:imageData];
//
// dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// //this will start the image loading in bg
// dispatch_async(concurrentQueue, ^{
// NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
//
// //this will set the image when loading is finished
// dispatch_async(dispatch_get_main_queue(), ^{
//
// cell.exhibitorImage.image = [UIImage imageWithData:imageData];
// [cell setNeedsDisplay];
//
// });
// });

NSString *ImageURL = [[parserDataContentArray objectAtIndex:indexPath.section] exhibitorImageObjectClass];
[cell.exhibitorImage setImageWithURL:[NSURL URLWithString:ImageURL]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];



if ([cell.exhibitorSponsorType.text isEqualToString:@"Gold"]) {
cell.exhibitorSponsorType.textColor = [UIColor colorWithRed:255/255.0 green:215/255.0 blue:0 alpha:1];

}

else if ([cell.exhibitorSponsorType.text isEqualToString:@"Silver"]){
cell.exhibitorSponsorType.textColor = [UIColor colorWithRed:192/255.0 green:192/255.0 blue:192/255.0 alpha:1];
}
else cell.exhibitorSponsorType.textColor = [UIColor colorWithRed:229/255.0 green:228/255.0 blue:226/255.0 alpha:1];

return cell;



}

谢谢最好的问候。

最佳答案

改为使用延迟加载文件,这里是您可以在此处找到它的引用以及它是如何实现的演示。

https://stackoverflow.com/a/18032907/1305001

[cell addSubview:[self addViewWithURL:ImageURL NFrame:CGRectMake(0, 0, 50, 50)]];

在cellForRow下面添加这个方法

-(UIView*)addViewWithURL:(NSString*)urlStr NFrame:(CGRect)rect
{
LazyLoad *lazyLoading;

lazyLoading = [[LazyLoad alloc] init];
[lazyLoading setBackgroundColor:[UIColor grayColor]];
[lazyLoading setFrame:rect];

[lazyLoading loadImageFromURL:[NSURL URLWithString:urlStr]];
return lazyLoading;
}

在LazyLoad.m文件的init方法中设置占位符为

-(id)init{
if (self==[super init]) {
[self setImage:[UIImage imageNamed:@"placeholder.png"]];
}
return self;
}

并将 LazyLoad.h 文件的父类(super class)从 UIView 更改为 UIImageView 为

@interface LazyLoad : UIImageView

关于ios - 当我使用 SDWebImage 时滚动不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18106084/

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