1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!{
didSet {
tableView.dataSource = self
tableView.delegate = self
}
}
struct Cellules {
var sections: String!
var items: [String]!
}
var tabCellules = [Cellules]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tabCellules = [Cellules(sections: "Section1", items: ["obj1","obj2"]), Cellules(sections: "Section2", items: ["obj1","obj2"])]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath as IndexPath) as UITableViewCell
cell.textLabel?.text = tabCellules[indexPath.section].items[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tabCellules[section].items.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return tabCellules.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return tabCellules[section].sections
}
} |
Partager