Так что в основном я пытаюсь использовать UITableView внутри ViewController, который будет ссылаться на представления из других UIViews.
Все виды отображаются, и все выглядит хорошо, за исключением TableView. Я установил tableView.datasource и tableView.delegate для себя. Я также проверил, использовал ли я тот же идентификатор повторного использования.
Ошибка: все представления отображаются, но представление таблицы просто черное. Вот код:
class MController: UIViewController, UITableViewDelegate, UITableViewDataSource{
let customNavBar = NavBarView()
let statusBarCover = UIView()
var tableView = UITableView()
lazy var kView: UIView = {
return InputView(frame: .init(x: 0, y: 0, width: view.frame.width, height: 100))
}()
override var canBecomeFirstResponder: Bool {
return true
}
override var inputAccessoryView: UIView? {
get {
return kView
}
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.contentInset.top = 120
tableView.verticalScrollIndicatorInsets.top = 120
tableView.keyboardDismissMode = .interactive
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "id")
view.addSubview(customNavBar)
customNavBar.backgroundColor = .yellow
customNavBar.anchor(top: view.safeAreaLayoutGuide.topAnchor, leading: view.leadingAnchor, bottom: nil, trailing: view.trailingAnchor, size: .init(width: 0, height: 120))
view.addSubview(statusBarCover)
statusBarCover.backgroundColor = .blue
statusBarCover.anchor(top: view.topAnchor, leading: view.leadingAnchor, bottom: view.safeAreaLayoutGuide.topAnchor, trailing: view.trailingAnchor)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "id", for: indexPath)
cell.textLabel?.text = "Testing"
return cell
}
}