Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created March 8, 2021 02:55
Show Gist options
  • Save KrauserHuang/ce3e76f53a823e51e5cbc882194aab4b to your computer and use it in GitHub Desktop.
Save KrauserHuang/ce3e76f53a823e51e5cbc882194aab4b to your computer and use it in GitHub Desktop.
extension ViewController: UITableViewDataSource {
// 顯示每一組有幾個cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return info[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell
if indexPath.section == 1 {
if indexPath.row == 0 {
cell.accessoryType = .checkmark
} else if indexPath.row == 1 {
cell.accessoryType = .detailButton
} else if indexPath.row == 2 {
cell.accessoryType = .detailDisclosureButton
} else if indexPath.row == 3 {
cell.accessoryType = .disclosureIndicator
}
}
cell.textLabel?.text = info[indexPath.section][indexPath.row]
return cell
}
// 有幾組section
func numberOfSections(in tableView: UITableView) -> Int {
return info.count
}
// 設定section的標題
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let title = section == 0 ? "籃球" : "棒球"
return title
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment