// // 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 : 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.black label.backgroundColor = UIColor.white 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 } }