Skip to content

Instantly share code, notes, and snippets.

enum TableSections: Int, CaseIterable {
case staticSection,
dynamicSection
}
override func numberOfSections(in tableView: UITableView) -> Int {
return TableSections.allCases.count
}
enum TableSections: Int, CaseIterable {
case staticSection,
dynamicSection
func title() -> String {
switch self {
case .staticSection:
return "Static Cells"
case .dynamicSection:
return "Dynamic Cells"
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return TableSections(rawValue: section)!.title()
}
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
if (indexPath.section == TableSections.staticSection.rawValue) {
return nil
} else {
return indexPath
}
}
@IBOutlet var puppyCell: UITableViewCell!
@IBOutlet var cupcakeCell: UITableViewCell!
@IBOutlet var unicornCell: UITableViewCell!
@IBOutlet weak var puppyLabel: UILabel!
var staticCells: Array<UITableViewCell>!
@IBOutlet var puppyCell: UITableViewCell!
@IBOutlet var cupcakeCell: UITableViewCell!
@IBOutlet var unicornCell: UITableViewCell!
@IBOutlet weak var puppyLabel: UILabel!
var staticCells: Array<UITableViewCell>!
var dynamicContent = ["One", "Two", "Three", "Four"]
let dynamicCellIdentifier = "Dynamic"
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == TableSections.dynamicSection.rawValue) {
return dynamicContent.count
} else {
return staticCells.count
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == TableSections.staticSection.rawValue) {
return staticCells[indexPath.row]
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: dynamicCellIdentifier, for: indexPath)
cell.textLabel?.text = dynamicContent[indexPath.row]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == TableSections.dynamicSection.rawValue) {
return dynamicContent.count
} else {
return staticCells.count
}
}