class ViewController: UITableViewController {
let dias = ["Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado","Domingo"]
var selecionados = [Bool]()
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dias.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = dias[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var selectedItem = indexPath
if let cell = tableView.cellForRow(at: indexPath)
{
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.checkmark
{
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none
}
else{
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
}
print(selectedItem.row)
}
I want to create a 'checkbox' I chose to do this through Tableview, however I have two difficulties, every time I select and unmark the line it's a print, I do not know if it's correct, however I wanted to add the selected lines in a variable and save with userDefaults, can anyone help me?