Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>just Change Little code in below method, Use Different -2 Identifier for each cell</p> <pre><code> -UITableViewCell *)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //here you should need to create different CellIdentifier for each cell of TableView NSString * cellIdentifier= [NsString stringWithFormat:@"cellIdentifier %d",[indexPath row]]; if(cell == nil) { //create TableView cell if no cell created previously //Here Create The UISWitch and Set Tag `[indexPath row]` } //Here You need To validate the Switch // validate stored state of Switch as TableView gets Scrolled Up or Down. if([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%d",[indexPath row]]]) { [mySwitch setOn:YES]; } else { [mySwitch setOn:NO]; } // remaining code will go as it is </code></pre> <p>}</p> <p><strong>EDIT: As <code>Paul.s</code> Described the Problem with the Above Approach, So in that case you should use separate model for holding the State of Switch.And of the little Solution for same is use NSUserDefaults for holding the state of UISwitch.</strong></p> <pre><code> //This is The Action of UISwitch, called whenever UISwitch value Changed - (void)onOffSwitch:(UISwitch*)sender{ //set True/False Flag As user Changed The Switch if(sender.isOn) [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:[NSString stringWithFormat:@"%d",[sender tag]]]; else [[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:[NSString stringWithFormat:@"%d",[sender tag]]]; [[NSUserDefaults standardUserDefaults] synchronize]; } </code></pre> <p>I am sure it'll help you.</p>
 

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