Я настраиваю табличное представление программно, я создаю страницу настроек с разделами, но по какой-то причине мои ячейки загружаются в одну и ту же строку, возможно, есть что-то простое, что мне не хватает, мне нужна помощь, чтобы решить эту проблему здесьСнимок того, что я получаю.
Мое намерение создать статические настраиваемые ячейки. Я изначально структурировал настраиваемые настраиваемые ячейки для загрузки без использования dequeueReusableCell, но он снова загружал ячейки в той же строке, я пытался с помощью массива ячеек настроить каждую строку с переключателемслучаи и имели аналогичный результат, и я закончил с очень простым массивом строк и настройкой ячеек в cellForRowAt, но это также не сработало.
import UIKit
class SettingsVC: UIViewController, StoryboardCoordinator , UITableViewDataSource, UITableViewDelegate {
//MARK: - Variables
var tableView = UITableView()
weak var coordinator: MainCoordinator?
let settings = ["Password Lock", "Unlock With TouchID", "Access Your Location?"]
//MARK: - TableView UI configuration
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return settings.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SettingsRow
cell.switchView.rowTitle.text = settings[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
override func viewDidLoad() {
super.viewDidLoad()
setup()
tableView.delegate = self
tableView.dataSource = self
tableView.register(SettingsRow.self, forCellReuseIdentifier: "cell")
tableView.allowsSelection = false
tableView.translatesAutoresizingMaskIntoConstraints = false
}
func setup() {
view.addSubview(tableView)
addConstraints()
}
func addConstraints(){
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),])
}
}