У меня есть UITableView
с несколькими ячейками данных, но при загрузке отображается только одна ячейка.Чтобы проверить, я добавил 4 строки в массив.
class LoadingDataViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableViewDataLoading: UITableView!
var dados = ["Vendas","Produtos","Pessoas","Animais"]
override func viewDidLoad() {
super.viewDidLoad()
print("View did load")
tableViewDataLoading.delegate = self
tableViewDataLoading.dataSource = self
tableViewDataLoading.layer.cornerRadius = 15.0
tableViewDataLoading.layer.borderColor = UIColor.vorazColor.cgColor
tableViewDataLoading.layer.borderWidth = 1.0
tableViewDataLoading.clipsToBounds = true
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dados.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellLoadingData") as! CellDataLoading
print("CELL: \(indexPath.row) - \(dados[indexPath.row])")
cell.lblDado.text = dados[indexPath.row]
cell.indicatorDado.startAnimating()
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: UITableViewAutomaticDimension))
let label = UILabel(frame: headerView.frame)
label.center = headerView.center
headerView.backgroundColor = UIColor.vorazColor
label.text = "Baixando dados..."
label.textColor = UIColor.white
headerView.addSubview(label)
return headerView
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let buttonCancel = UIButton(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: UITableViewAutomaticDimension))
buttonCancel.backgroundColor = UIColor.vorazColor
buttonCancel.setTitle("Cancelar", for: .normal)
buttonCancel.addTarget(self, action: #selector(cancelar), for: .touchUpInside)
return buttonCancel
}
@objc func cancelar(_ sender : UIButton) {
self.dismiss(animated: true, completion: {})
}
}
class CellDataLoading : UITableViewCell {
@IBOutlet weak var imgCheckDado: UIImageView!
@IBOutlet weak var indicatorDado: UIActivityIndicatorView!
@IBOutlet weak var lblDado: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
}
Результат:
Раскадровка:
Obs .: метка представления заголовка не отображается, и этот ViewController представлен в виде всплывающего окна.