How save selected switch option

Posted by Rkm on Stack Overflow See other posts from Stack Overflow or by Rkm
Published on 2010-12-27T09:44:52Z Indexed on 2010/12/27 9:54 UTC
Read the original article Hit count: 336

Filed under:
|

System UIviewcontroller has button , Tap on button i need to fire Info Tableviewcontroller. Tableviewcontroller itself UISwitch. My question is I need to save last selected switch option ON/OFF in UISwitch how to set my control.

@implementation Info

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
  {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

 if (indexPath.section) 
 {
   cell.textLabel.text = @"Sounds";
   cell.selectionStyle = UITableViewCellSelectionStyleNone;
   UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
   cell.accessoryView = switchView;
   [switchView setOn:NO animated:NO];
   [switchView addTarget:self action:@selector(switchChanged_Sounds:) forControlEvents:UIControlEventValueChanged];
   [switchView release];
   return cell ;
 }


}

- (void) switchChanged_Sounds:(id)sender
{
    UISwitch* switchControl = sender;
    NSLog( @"The switchChanged_Sounds is %@", switchControl.on ? @"ON" : @"OFF" );
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiswitch