An amazing project that generates micro reports from tournament results
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pa-tournament-stats/TournamentStats/UI/DataSourceWrapper.swift

63 lines
1.8 KiB

//
// Array+UITableDataSource.swift
// TournamentStats
//
// Created by Laurent Morvillier on 05/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
class DataSourceWrapper<T : ColumnRepresentable> : NSObject, UITableViewDataSource, UITableViewDelegate {
var columnRepresentables: [T]
init(array: [T]) {
self.columnRepresentables = array
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("numberOfRowsInSection = \(self.columnRepresentables.count)")
return self.columnRepresentables.count + 1 // + 1 for header
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! StackTableCell
var columns: [String]
var font: UIFont
switch indexPath.row {
case 0:
columns = T.headers()
font = UIFont.boldSystemFont(ofSize: 16.0)
default:
let cr = self.columnRepresentables[indexPath.row - 1]
columns = cr.colums()
font = UIFont.systemFont(ofSize: 16.0)
}
columns.forEach { value in
let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30))
label.textColor = UIColor.white
label.backgroundColor = UIColor.clear
label.text = value
label.font = font
cell.stackView.addArrangedSubview(label)
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 32.0
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.1
}
}