小编sof*_*n 9的帖子

在视图控制器Swift的UITableView中加载多个UICollectionView

我正在构建一个iOS应用程序,其中UITableView中有4种不同的UICollectionViewn设计。

UICollectionViewCell类名称是:DealCollectionViewCell,FilterCollectionViewCell,ComboCollectionViewCell,BusinessCollectionViewCell

UITableViewCell类名称是:DealTableViewCell,BusinessTableViewCell,FilterTableViewCell,ComboTableViewCell

下面是UIViewController类代码(类名HomeViewControllerr)

类扩展

UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource
Run Code Online (Sandbox Code Playgroud)

对于UITableView

func tableView(_ tableView:UITableView,numberOfRowsInSection部分:Int)-> Int {return 4}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if  indexPath.row == 0
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DealTableViewCellId") as! DealTableViewCell

        return cell
    }
    else if indexPath.row == 1
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "FilterTableViewCellId") as! FilterTableViewCell

        return cell
    }
    else if indexPath.row == 2
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ComboTableViewCellId") as! ComboTableViewCell

        return cell
    }
    else
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: …
Run Code Online (Sandbox Code Playgroud)

uitableview ios uicollectionview swift

1
推荐指数
1
解决办法
74
查看次数

标签 统计

ios ×1

swift ×1

uicollectionview ×1

uitableview ×1