private var tableView: UITableView!
var sections = [
[localizedString(.settings_notifications_beforeOneHourStart), localizedString(.settings_notifications_startFasting)],
[localizedString(.settings_notifications_inMiddle)],
[localizedString(.settings_notifications_beforeOneHourFinish), localizedString(.settings_notifications_finishFasting)]
]
override func viewDidLoad() {
super.viewDidLoad()
//self.view.backgroundColor = .white;
self.navigationItem.title = "Уведомления";
tableView = UITableView(frame: .zero, style: .grouped)
tableView.separatorStyle = .none;
tableView.sectionIndexBackgroundColor = .blue
tableView.backgroundColor = .white;
tableView.dataSource = self
tableView.delegate = self
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.activate([
tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].count
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
print("heightForHeaderInSection")
return 30
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
print("heightForFooterInSection")
return 30
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let v = UIView(frame: CGRect(x: 15, y:0, width: tableView.frame.width, height: 1))
///v.backgroundColor = .lightGray
return v
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = sections[indexPath.section][indexPath.row]
cell.textLabel?.font = UIFont.systemFont(ofSize: 17)
let switchView = UISwitch(frame: .zero)
switchView.setOn(false, animated: true)
switchView.tag = indexPath.row
switchView.addTarget(self, action: #selector(self.switchDidChange(_:)), for: .valueChanged)
cell.accessoryView = switchView;
return cell
}
@objc func switchDidChange(_ sender: UISwitch){
print("sender is \(sender.tag)")
}
}
ну такое себе
Зачем эта простыня тут?
Обсуждают сегодня