Post

Replies

Boosts

Views

Activity

Reply to How to save the state of a Switch
I figured out how to save the state of the switch when the state of the switch is changed. Thanks for your help on getting me there. class SettingsCustomCell: UITableViewCell { //... @IBAction func switchValueChanged(_ sender: UISwitch) {         state?.settingValue = sender.isOn         let defaults = UserDefaults.standard         defaults.set(quickAddSwitch.isOn, forKey: "quickAdd")     } } class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { //... override func viewDidLoad() {         super.viewDidLoad()         cellStates = [             SettingsState(settingLabel: "Quick Add", settingValue: (UserDefaults.standard.bool(forKey: "quickAdd")))         ]     } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource {          var data = [Settings_Custom_Cell]()          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return data.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]         let cell = table.dequeueReusableCell(withIdentifier: "cell") as! Settings_Custom_Cell         let array = data[indexPath.row]         cell.textLabel?.text = array.settingLabel.text         cell.settingValue.isOn = array.settingValue.isOn         cell.textLabel?.numberOfLines = 0         cell.textLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping         cell.textLabel?.font = UIFont.systemFont(ofSize: 20)         return cell     }     @IBOutlet weak var table: UITableView!     override func viewDidLoad() {         super.viewDidLoad()     }      } I am not sure if I am on the right track but what do I put in the 'settingValue' value in data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource {          var data = [Settings_Custom_Cell]()          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return data.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]         let cell = table.dequeueReusableCell(withIdentifier: "cell") as! Settings_Custom_Cell         let array = data[indexPath.row]         cell.textLabel?.text = array.settingLabel.text         cell.settingValue.isOn = array.settingValue.isOn         cell.textLabel?.numberOfLines = 0         cell.textLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping         cell.textLabel?.font = UIFont.systemFont(ofSize: 20)         return cell     }     @IBOutlet weak var table: UITableView!     override func viewDidLoad() {         super.viewDidLoad()     }      } I am not sure if I am on the right track but what do I put in the 'settingValue' value in data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21