UICollectionView布局,带有SearchBar的节标题和标题的另一个动态节标题

时间:2019-02-06 07:01:29

标签: ios swift iphone uicollectionview uicollectionviewlayout

我想为集合视图创建2个标题。

第一个标头是UISearchController,该节的标头用于我从JSON获得的类别

这是JSON示例

"tag": "req_kingdom_classification",
"success": "1",
"error": "0",
"data": [
    {
        "Category": "Animalia",
        "SubCategory": "Mamals",
        "imagePath": "Mamals.jpg",
        "keyword": "",
        "activity": "AA"
    },
    {
        "Category": "Animalia",
        "SubCategory": "Reptile",
        "imagePath": "Reptile.jpg",
        "keyword": "",
        "activity": "AA"
    },{
        "Category": "Plantae",
        "SubCategory": "Embryophyta",
        "imagePath": "Embryophyta.jpg",
        "keyword": "",
        "activity": "PP"
    },
    {
        "Category": "Bacteria",
        "SubCategory": "Streptomyces",
        "imagePath": "Streptomyces.jpg",
        "keyword": "",
        "activity": "BB"
    }, ...
]

该图像已经在设备内部,因为我已经调用了API来获取图像。

这就是我要创建的

------------------------------------------------------------- 
|                          SearchBar                        |
-------------------------------------------------------------
|                          Category1                        |
-------------------------------------------------------------
|     Category1.imagePath1    |     Category1.imagePath2    |
|    Category1.SubCategory1   |    Category1.SubCategory2   |
|                                                           |
|     Category1.imagePath3    |     Category1.imagePath4    |
|    Category1.SubCategory3   |    Category1.SubCategory4   |
-------------------------------------------------------------
|                          Category2                        |
-------------------------------------------------------------
|     Category2.imagePath1    |     Category2.imagePath2    |
|    Category2.SubCategory1   |    Category2.SubCategory2   |
|                                                           |
|     Category2.imagePath3    |     Category2.imagePath4    |
|    Category2.SubCategory3   |    Category2.SubCategory4   |
-------------------------------------------------------------
...

我使用UISearchBar搜索每个SubCategory

如何使用Swift像这样自定义UICollectionView

1 个答案:

答案 0 :(得分:0)

我们在iOS的集合视图中没有页眉和页脚部分。 但您可以在集合单元中管理tableview,因为在table视图中具有页眉和页脚视图。

我希望如此可以解决您的问题。