Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an example of using <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html" rel="nofollow"><code>NSUserDefaults</code></a></p> <pre><code>NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; //Set a value [defaults setBool:YES forKey:@"check1"]; //Save immediately [defaults synchronize]; //Retrieve the value for check1 BOOL retrieved = [defaults boolForKey:@"check1"]; </code></pre> <p><strong>Update</strong></p> <p>If your dataArray only contains dictionaries with bools and strings in it then you can save the entire dataArray to <code>NSUserDefaults</code>. The following code is untested but should be close to what you will need to persist your values.</p> <pre><code>-(id)yourInitMethod { dataArray = [(NSArray*)[[NSUserDefaults standardUserDefaults] objectForKey:@"dataArrayKey"] mutableCopy]; //Replace dictionaries with a mutable copy for(int i = 0; i &lt; [dataArray count]; i++) { //Your dictionary that you want to be mutable NSMutableDictionary *aCopy = [(NSDictionary*)[dataArray objectAtIndex:i] mutableCopy]; [dataArray replaceObjectAtIndex:i withObject:aCopy]; [aCopy release]; } } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row]; BOOL checked = [[item objectForKey:@"checked"] boolValue]; [item setObject:[NSNumber numberWithBool:!checked] forKey:@"checked"]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; //Save the updated data array [defaults setObject:dataArray forKey:@"dataArrayKey"]; [defaults synchronize]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload