Ios 如何在多个UITableView和CollectionView中使用API动态加载数据

Ios 如何在多个UITableView和CollectionView中使用API动态加载数据,ios,swift3,Ios,Swift3,希望使用集合视图和表视图中的api加载数据 表格视图将处理垂直滚动。每种类型(星期)都是一个包含一个标题和一个单元格的表格部分。关键实际上是在表视图行中嵌套集合视图。只要记住将集合视图数据源指向表单元格而不是视图控制器,一切都会很好 已实现以下代码 控制器-时间表VC 在显示静态数据的控制器中 import UIKit class TimetableVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

希望使用集合视图和表视图中的api加载数据

表格视图将处理垂直滚动。每种类型(星期)都是一个包含一个标题和一个单元格的表格部分。关键实际上是在表视图行中嵌套集合视图。只要记住将集合视图数据源指向表单元格而不是视图控制器,一切都会很好

已实现以下代码
控制器-时间表VC
在显示静态数据的控制器中

import UIKit

class TimetableVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

     var categories = \["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"\]

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return categories.count
//              return 1
    }


    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return categories\[section\]
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return categories.count
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

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

        return cell
    }

}
类别:

// Collectionview data showing

import UIKit

class CategoryRow : UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    @IBOutlet weak var collectionView: UICollectionView!

   // var Array = [String]()

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        // add no of item in the table like 2,3,5
        return 10
    }


    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videoCell", for: indexPath) as! VideoCell
//        return cell

        // get a reference to our storyboard cell
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "itemCell", for: indexPath as IndexPath) as! VideoCell

        var Label1 =  cell.viewWithTag(1) as! UILabel
        Label1.text = "Subject"

        var Label2 =  cell.viewWithTag(2) as! UILabel
        Label2.text = "Teacher"

        var Label3 =  cell.viewWithTag(3) as! UILabel
        Label3.text = "Time"


        // Use the outlet in our custom class to get a reference to the UILabel in the cell
        //cell.myLabel.text = self.items[indexPath.item] 
//        cell.backgroundColor = UIColor.cyan // make cell more visible in our example project

        return cell

    }    


    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let itemsPerRow:CGFloat = 4
        let hardCodedPadding:CGFloat = 0
        //        let itemWidth = (collectionView.bounds.width / itemsPerRow) - hardCodedPadding
        //        let itemHeight = collectionView.bounds.height - (2 * hardCodedPadding)
        let itemWidth = 100
        let itemHeight = 100
        return CGSize(width: itemWidth, height: itemHeight)
    }

}
注意:请帮帮我。我已经实现了表视图和集合视图。我想使用api响应动态显示带有集合视图数据的表头

输出: