Note that there are some explanatory texts on larger screens.

plurals
  1. POSave and Load UISwitch state in TableView
    text
    copied!<p>I want to save the switch state. I created custom cell class witch print one Switch on label but there is problem that if i search some text then Table View reload and my selected switch State is going to change, Is it possible to Maintain that state ? </p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ .... selectionStyle = UITableViewCellSelectionStyleNone; CfResultFatch *temp = [result objectAtIndex:indexPath.row]; NSLog(@"%@",temp.complanName); //[cell.switchOnOff setOn:NO]; [cell.switchOnOff setTag:indexPath.row]; [cell.switchOnOff addTarget:self action:@selector(selectUser:)forControlEvents:UIControlEventValueChanged]; [cell.switchOnOff setTag:indexPath.row]; cell.lblUserName.text = temp.complanName; cell.textFld.text = temp.cipd; return cell; } </code></pre> <p>//selectUser which is call when switch state change</p> <pre><code>-(IBAction)selectUser:(UISwitch*)sender{ if(sender.on) { [selectedpet addObject:[result objectAtIndex:sender.tag]]; }else{ NSLog(@"%@",sender); for(int j=0;j&lt;[selectedpet count]; j++) { CfResultFatch *temp = [result objectAtIndex:sender.tag]; CfResultFatch *temp1= [selectedpet objectAtIndex:j]; if([(temp.complanName)isEqualToString:(temp1.complanName)]) { [selectedpet removeObjectAtIndex:j]; } } } } </code></pre> <p>//and Search in searchBar this methode is call when search some text and the data is change from data base problem is here is i select 0 and 1 index switch on and then search some text, the new data in table view come with 0 and 1 index ON,how to maintain it and how to get my previous state of Switch </p> <pre><code>- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ NSString *weburl = [NSString stringWithFormat:@"%@%@", @"http://192.168.1.196/ravi/searchUser.php?mname=",searchText]; NSURL *url = [NSURL URLWithString:weburl]; NSData *data =[NSData dataWithContentsOfURL:url]; [self getData:data]; [temptab reloadData]; } </code></pre> <p>And ya. sorry for my poor english </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