ios - Not sure why NSUserdefaults is not saving the results? -


I am trying to save the check and remove the uncheck tableclass in NSUserdefaults, but it seems that the NSLog In the loop, he is not called for sure, why is there anything wrong in this code? (Everything shows up right and cells are checked and unchecked)

  - (zero) tableview: (UITableView *) tableview was selected by endindex: path: (NSIndexPath *) IndexPath {// setting up nsUser UserDefaults = [NSUserDefaults standard user default]; // current line text UITableViewCell * cell = [table view cellarrowoutindexpath: indexpath]; NSString * cellname = cell.textLabel.text; // Check that the existing row is selected; boolean isNowChecked = NO; If ([tableview cellphonerexexpath: indexpath]. Asserty type == uTitViewkelEsourceCrackmark) {Hainoukank = Yes; } If (hanocaqed) {nslog (@ "unchecking"); [Tableview cellphoneUroutexpath: indexpath]. Asset type = UITableViewCellAccessoryNone; // Highlights from selection [select the tableview: RouteTindPath: indexpath animated: yes]; // nsdefaults from NSMutableArray * arrayOfCategories = [userDefaults objectForKey: @ "categories"]; NSMutableArray * categories selected; // remove nsuserdefaults // Add to nsuserdefaults (arrayOfCategories in NSString * o) {NSLog (@ "% @", o); If ([o eccoltostring: selenam]) {} other {[categories selected object: o]; }} // set nsdefaults [userDefaults set object: selected for categories: @ "categories"]; [User default synchronize]; } And {nslog (@ "checking"); [Tableview cellphoneEurrentExpath: IndexPath]. Sasserty Type = UITTVUKEELAsSureRich Mark; // Highlights from selection [select the tableview: RouteTindPath: indexpath animated: yes]; NSMutableArray * categories selected; // Add to array [Categories selected addObject: cellName]; // nsdefaults from NSMutableArray * arrayOfCategories = [userDefaults objectForKey: @ "categories"]; // Add to nsuserdefaults (NSString * array in array off range) {NSLog (@ "% @", o); [Categories selected object: o]; } // set nsdefaults [userDefaults set object: selected for categories: @ "categories"]; [User default synchronize]; }}    

Replace this line, otherwise you have one unrelated array:

  NSMutableArray * categories selected; From   

to:

  NSMutableArray * selected categories [= NSMutableArray alloc] init];   

Update: After watching your code there are actually a few things that should be improved.

  1. You should load the list of check categories in a single viewDidLoad and keep the list in a frequency variable.
  2. It is not a good idea to see if the cell is currently being investigated, your data model should tell you which rows are examined.
  3. You have several duplicate codes to toggle the status of a cell checked.
  4. Keep track of checked cells.

    Try the following changes:

    Add an NSMutableSet example variable to your class:

      NSMutableSet * _checkedCategories;  ViewDidLoad , load set:  
      NSArray * checked categories = [[NSUserDefault standardUserDefaults] objectForKey: @ "Categories" ]; If (Checked categories) {_ Checked Category = [[NSMUtablesSatLock] InitVthArere: Checked Categories]; } Other {_ checked classification = [[NSMutableSat Elok] Init]; }   

    Update your didSelectRow method now:

      - (zero) tableview: (UITableView *) tableview select SelectionRowAtIndexPath: (NSIndexPath *) index {NSString * cellName = ...; // Get the name of the cell from your data model, cell is not BOOL checked = [_checked categories include objects: cellname]; UITableViewCell * cell = [tableView cellarrowoutindexpath: indexpath]; If (checked) {{Remove checked-categories: Object: cellname}; // Unchecked cell now Accessory type = UITableViewCellAccessoryNone; } Other {{_checked categories addObject: cellName]; // Checked cell now Accessory type = UITableViewCellAccessoryCheckmark; } [Select Table View: RouteAet Path: Animated Pathway: Yes]; [[NSUISIR default standard standard default] Set object: [_Cheed content for all objects]: @ "categories"]; Synchronize [[NSUserDefaults Standard User Defaults]]; }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -