Dynamic UITableView Grouped Cells

I created these settings tableviewusing static cells and grouped style:

enter image description here

I would like to recreate the same tableview, but this time I would like to use dynamic cells . I know how to work with dynamic cells, but I don’t know how I can set different sections with different headers.

I need 4 sections (status, queue, type, degree), and each section has an indefinite number of cells (this number is equal to the length of the data array).

Can someone post a complete example, please? I could not find documentation that could help me.

+4
source share
2

TableViewDemo .

 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 4
}

-

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return "title" // Use the titleForHeaderInSection index
}

BR

+2

numberOfSectionsInTableView, numberOfRowsInSection, titleForHeaderInSection cellForRowAtIndexPath

let section = ["section1", "section2"]
let cellsInSection = [["section1cell1", "section1cell2"], ["section2cell1", "section2cell2"]]

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return section.count
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return cellsInSection[section].count
}

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

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    if indexPath.section == 0 {

        let cell = tableView.dequeueReusableCellWithIdentifier("section1", forIndexPath: indexPath) as! SectionOneTableViewCell

        return cell
    } else if indexPath.section == 1 {

        let cell = tableView.dequeueReusableCellWithIdentifier("section2", forIndexPath: indexPath) as! SectionTwoTableViewCell
        return cell
    }
}
+1

All Articles