Skip to content

Instantly share code, notes, and snippets.

@msoffack
Created February 10, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msoffack/0a88c9cbe8bbe79ecfc263c9eed102b6 to your computer and use it in GitHub Desktop.
Save msoffack/0a88c9cbe8bbe79ecfc263c9eed102b6 to your computer and use it in GitHub Desktop.
Table view
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let menSports = ["Basketball", "Baseball", "Soccer"]
let womenSports = ["Basketball", "Soccer", "Softball", "Volleyball"]
let womenmenSports = ["Track & Field"]
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0{
return 3
}else if section == 1{
return 4
}else {
return 1
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell
if indexPath.section == 0{
cell.myImage.image = UIImage(named: menSports[indexPath.row]+".png")
cell.myLabel.text = menSports[indexPath.row]
cell.button1.setTitle("Schedule", for: .normal)
cell.button2.setTitle("Roster", for: .normal)
} else if indexPath.section == 1 {
cell.myImage.image = UIImage(named: womenSports[indexPath.row]+".png")
cell.myLabel.text = womenSports[indexPath.row]
cell.button1.setTitle("Schedule", for: .normal)
cell.button2.setTitle("Roster", for: .normal)
}else{
cell.myImage.image = UIImage(named: womenmenSports[indexPath.row]+".png")
cell.myLabel.text = womenmenSports[indexPath.row]
cell.button1.setTitle("Schedule", for: .normal)
cell.button2.setTitle("Roster", for: .normal)
}
return (cell)
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0{
return "MEN"
}else if section == 1{
return "WOMEN"
}else {
return "WOMEN & MEN"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment