Thursday, 15 September 2011

ios - Swift - Save cell selection in NSUserDefaults -


Currently, I have a to-do list app when selecting a row, alpha Dims, this indicates that the work is selected or "complete" how I was looking for strictly here to save the selected cell state for the NSUserDefaults

My ViewController .

  Class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {var error = NSUserDefaults.standardUserDefaults () @IBOutlet Weaker on toDoListTable: UITableView! ViewDidLoad () {super.viewDidLoad () if defaults.objectForKey ("toDoList")! = Zero {toDoList = defaults.objectForKey ("toDoList") as [string]}} override function didReceiveMemoryWarning () {super.didReceiveMemoryWarning (Override Function) // Any Resource Disposal which can be reproduced . } Function Table View (Table View: UITableView, numberOfRowsInSection section: Int) - & gt; Int {return toDoList.count} function tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - & gt; UITableViewCell {cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier ("cell", forIndexPath: indexPath) UITableViewCell return cell} func tableView (tableview: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {var Selected cell = tableView.cellForRowAtIndexPath (indexPath)! SelectedCell.contentView.alpha = 0.3} function tableView (tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {var deselectedCell = tableView.cellForRowAtIndexPath (indexPath)! deselectedCell.contentView.alpha = 1.0} function tableView (tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {if editingStyle == UITableViewCellEditingStyle.Delete {toDoList.removeAtIndex (indexPath.row) toDoListTable.deleteRowsAtIndexPaths ([indexPath], (Ad animated: boole) {toDoListTable.reloadData ()}}  

I believe that I'm just calling an issue / trying to figure out where is any The help will be greatly appreciated.

Edit ** I now save the contents stored from a UITextField .

Is that a problem that does not save it?

You can try to see it immediately on the disk that it makes a difference, though it Must not be required.

  NSUserDefaults.standardUserDefaults (.) SetObject (for indexPath.row, forKey: "Selection") NSUserDefaults.standardUserDefaults (). Synchronize ()  

No comments:

Post a Comment