在表格视图中滚动时图像重复单元格

图像在 tableview 中显示不正确,我有两个 Json Api(小学/高中)学校。我可以附加两个 Json api 数据并显示到 tableview,tableview 工作正常它显示两个(小学/高中)学校数据。当我可以滚动 tableview 时,图像正在跳跃,并且图像在 tableview 的图像视图中加载速度非常慢。

在滚动 tableview 之前它的显示是这样的

在此处输入图片说明

在此处输入图片说明

滚动 tableview 后,它显示如下

滚动图像跳跃后,

在此处输入图片说明

这是代码

     var kidsdata = [KidDetails]()

    func getprimarydata(_firsturl: String,firstid:String,updatedate:String)
    {


                                        if errorCode == "0" {

                                      if let kid_list = jsonData["students"] as? NSArray {

                                      self.kidsdata.removeAll()

                                      for i in 0 ..< kid_list.count {

                                      if let kid = kid_list[i] as? NSDictionary {


                                      let imageURL = url+"/images/" + String(describing: kid["photo"]!)

                                      self.kidsdata.append(KidDetails(
                                                            name:kid["name"] as? String,
                                                            photo : (imageURL),
                                                            standard: ((kid["standard"] as? String)! +  "std" + " " + (kid["section"] as? String)! + " section ")
                                                            ))}}}}
 }


      func gethighdata(_secondurl:String ,secondid:String,updatedate:String)
        {
         if errorCode == "0" {

                                if let kid_list = jsonData["students"] as? NSArray {
                                    for i in 0 ..< kid_list.count {


                                        if let kid = kid_list[i] as? NSDictionary {

                                            let imageURL = url+"/images/" + String(describing: kid["photo"]!)

                                            self.kidsdata.append(KidDetails(
                                                name:kid["name"] as? String,
                                                photo : (imageURL),

                                    standard: ((kid["standard"] as? String)! + "th" + " " + (kid["section"] as? String)! + " section ")
                                                )
                                            )
                                        }
                                    }


                                self.do_table_refresh()
                            }
                            }
    }


        func do_table_refresh()
        {

            DispatchQueue.main.async(execute: {

                self.TableView.reloadData()

                return
            })

        }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
          let cell =
                tableView.dequeueReusableCell(
                    withIdentifier: "cell", for: indexPath) as! DataTableViewCell
            cell.selectionStyle = .none

            cell.ProfileImage?.image = nil

            let row = (indexPath as NSIndexPath).row


            let kid = kidsdata[row] as KidDetails

            cell.NameLabel.text = kid.name

            cell.ProfileImage.image = UIImage(named: "profile_pic")

            cell.ProfileImage.downloadImageFrom(link:kid.photo!, contentMode: UIViewContentMode.scaleAspectFill)
            cell.ClassNameLabel.text = kid.standard
           return cell
        }

我做错的地方请帮助我....!

尼尔

AlamofireImage 处理得很好。https://github.com/Alamofire/AlamofireImage

import AlamofireImage

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
              let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! DataTableViewCell
                cell.selectionStyle = .none

                let kid = kidsdata[indexPath.row] as KidDetails


                cell.NameLabel.text = kid.name
                cell.ClassNameLabel.text = kid.standard

                // assuming cell.ProfileImage is a UIImageView
                cell.ProfileImage.image = nil

                let frame = CGSize(width: 50, height: 50)
                let filter = AspectScaledToFillSizeWithRoundedCornersFilter(size: frame, radius: 5.0)

                cell.ProfileImage.af_setImage(withURL: urlToImage, placeholderImage: nil, filter: filter,
                                      imageTransition: .crossDissolve(0.3), runImageTransitionIfCached: false)

               return cell
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我的表格视图在滚动时重用选定的单元格-在SWIFT中

表格视图单元格中的圆形图像

在Swift中,当定向发生时,如何在表格视图中看到相同的单元格?

快速在表格视图中选择单个单元格

表格视图单元格复选标记在滚动时更改位置

无法通过heightForRowAt获取表格视图中的单元格

滚动后重复使用单元格后,如何在表格视图单元格中保持值?

滚动时,集合视图单元格重复

在表格视图中删除或重新排列单元格时的动画

表格视图中重叠的单元格

在动态表格视图中添加静态单元格

滚动表格视图并长按选中的单元格

自定义表格视图单元格图像失真

为什么在添加单元格时表格视图中的单元格会调整大小?

iOS在表格视图中选择的单元格视图

滚动uitableview时重复的单元格

滚动后,表格视图单元格的内容发生更改

当我点击表格视图中的任何单元格时,单元格未替换

如何获取以编程方式在放置在iOS中的表格视图的单元格和单元格索引路径中的滚动视图中创建的视图的位置

使用动态单元格高度时,将表格视图滚动到底部

表格视图单元格中的图像

表格视图中单元格之间的快速距离

使用SearchBar时,表格视图单元格中的图像

iOS对表格视图单元格内的图像视图的约束在滚动时放错了位置

Swift:滚动时标签和图像的 UICollectionView 单元格重复

由于表格视图中可重复使用的单元格,当它滚动出视图时丢失 Youtube 播放器

表格视图中的单元格没有响应

使用 UIImage 滚动时表格视图单元格滞后

根据表格的单元格内容动态适应表格视图的高度到滚动视图中