首页 > 解决方案 > uitableview 中的 uicollection 视图始终显示 0 array.lenth 并且从不加载数据

问题描述

我在我的项目中遇到了一个问题,基本上我想在 uitableview 中使用 uicollectionview 但它总是显示 0 个数组 .count in numberOfItemsInSection of collectionview 这里是 tableview 单元格内的集合视图代码

      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: 
        Int) -> Int {
        print(experience_array_skill.count)// always show 0 
        return experience_array_skill.count
          
         }

       func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: 
                IndexPath) -> UICollectionViewCell {
              let cell = collects.dequeueReusableCell(withReuseIdentifier: "shorlist_exp_cell", 
         for: indexPath as IndexPath) as! shorlist_exp_cell
           cell.btn1.text = self.experience_array_skill[indexPath.row].experience_in
        
            cell.layer.cornerRadius = 15.0
            cell.clipsToBounds = true
                   
                return cell
           }
        
        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: 
       IndexPath) {
                
        }

我的 JSON

      {
       "message": "candidate job listing",
        "status": true,
        "data": [
       {
        "id": 1,
        "company_name_shown_job": "xyz company",
        "job_title": "Android Developer",
        "job_description": null,
        "experience_tags": [
            {
                "id": 2,
                "employer_job_post_id": 1,
                "experience_in": "Android"
            },
            {
                "id": 3,
                "employer_job_post_id": 1,
                "experience_in": "Php"
            }
        ]
    },
    {
        "id": 2,
        "company_name_shown_job": "Abc company",
        "job_title": "Web Developer",
        "job_description": "<p>Lorem ipsum dolor sit amet,laborum.</p>",
        "experience_tags": [
            {
                "id": 4,
                "employer_job_post_id": 2,
                "experience_in": "Swift"

            },
            {
                "id": 5,
                "employer_job_post_id": 2,
                "experience_in": "Java"
            }
        ]
    }
]
}

在上面的 JSON 数据中是我的 uitableview 的数组,而

标签: iosswiftxcodeuitableviewcollectionview

解决方案


您从 tableview 传递到experience_array_skill数组的数据始终为零,因此您得到的计数为 0。检查您将数据传递到您的experience_array_skill数组的代码。


推荐阅读