UITableView 的平滑滚动 [英] Smooth scrolling of UITableView

查看:32
本文介绍了UITableView 的平滑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UITableView 出现平滑滚动问题.任何人都可以帮助我问题出在哪里?我写的代码是这样的-

I have a smooth scrolling problem with the UITableView. Can anyone help me where is the problem? The code I have written is this-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomTableCell";
    LabTestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil];

        cell = [nib objectAtIndex:0];

    }//cell.txtHeading.text=@"hello";

    cell.txtHeading.text=[[_ResponseDic valueForKey:@"title"]objectAtIndex:indexPath.row];

    cell.txtdescribtion.text=[[_ResponseDic valueForKey:@"description"]objectAtIndex:indexPath.row];

    cell.txtPrice.text=[[_ResponseDic valueForKey:@"purchase_price"]objectAtIndex:indexPath.row];

    cell.txtLabName.text=[[_ResponseDic valueForKey:@"brand"]objectAtIndex:indexPath.row];
    
    NSString *path=@"https://www.fingerfry.com/pharmgo/uploads/product_image/";
    NSString *url=[path stringByAppendingString:[[_ResponseDic valueForKey:@"main_image"]objectAtIndex:indexPath.row]];

    NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
    UIImage* image = [[UIImage alloc] initWithData:imageData];
    
    cell.image.image=image;

    return cell;
}

推荐答案

首先安装 pod:

pod 'SDWebImage/WebP', '~>3.7' in pod file. 

然后你必须导入:

#import <SDWebImage/UIImageView+WebCache.h>

写下面的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomTableCell";
    LabTestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil];

        cell = [nib objectAtIndex:0];

    }//cell.txtHeading.text=@"hello";

    cell.txtHeading.text=[[_ResponseDic valueForKey:@"title"]objectAtIndex:indexPath.row];

    cell.txtdescribtion.text=[[_ResponseDic valueForKey:@"description"]objectAtIndex:indexPath.row];

    cell.txtPrice.text=[[_ResponseDic valueForKey:@"purchase_price"]objectAtIndex:indexPath.row];

    cell.txtLabName.text=[[_ResponseDic valueForKey:@"brand"]objectAtIndex:indexPath.row];

    [cell.image sd_setImageWithURL:[NSURL URLWithString:[obj valueForKey:IMAGE_KEY]] placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

        }];

    return cell;
} 

参考链接:https://github.com/rs/SDWebImage

这篇关于UITableView 的平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆