Save UITableViewCell configuration

50 Views Asked by At

I made an iOS App which includes an UITableView. It's possible to tap the cell. If the user tapped the cell an accessory type will be shown.

My question is: How can I save the cell configuration? I'd like to save all cells which were tapped / display the accessory type. If the UITableView reloads the accessory type(s) should still be presented.

I thought about to do this with NSUserDefaults but don't know how to do it.

If someone of you guys know how to do it and would like to help me you would help me a lot.

1

There are 1 best solutions below

0
gutenmorgenuhu On

Try the following:

// Get the UserDefaults
let defaults = NSUserDefaults.standardUserDefaults()

// Check if any old values are already saved:
if let savedEntity = defaults.objectForKey("myKey"){
    if countElemenets(savedEntity) > 0 {
        return savedEntity
    }
}

// Create new saved default:
defaults.setValue(objectToSave, forKey: "myKey")

There are several other types you can save/fetch beside AnyObject. Please check the Documentation for NSUserdefaults