0
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)
}
Well I want to create a 'checkbox' I chose to do this through Tableview, but I have two difficulties, every time I select and uncheck the line it gives a print, I do not know if it is correct, but I wanted to add the selected lines in a variable and save with userDefaults, someone can help me?