【问题标题】:uicollection view inside uitableview always show 0 array.lenth and never load datauitableview 中的 uicollectionview 始终显示 0 array.length 并且从不加载数据
【发布时间】:2020-06-20 09:25:21
【问题描述】:

我在我的项目中遇到了一个问题,基本上我想在 uitableview 中使用 uicollectionview,但它总是显示 0 个数组。collectionview 的 numberOfItemsInSection 中的计数这里是 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 的数组,而

【问题讨论】:

    标签: ios swift xcode uitableview collectionview


    【解决方案1】:

    我认为这里的问题是这个数组 experience_array_skill 不包含任何值。您如何将数据添加到 experience_array_skill 数组由于该数组没有值,因此您将 0 作为计数值。因此,也许一旦查看该部分,如果找不到,请发布该部分代码。上面的代码似乎是正确的。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多