can anyone tell me how to use switch? [duplicate]

2019-03-07 04:12发布

Possible Duplicate:
How to apply setting by toggle switch?

I want to use switch button to toggle on and off of a setting

can anyone tell me how to set it up? I already have the following code

Thanks!

declaration

- (IBAction) changeMode:(id)sender;

implementation

-(IBAction) changeMode:(id)sender
{
}

1条回答
一夜七次
2楼-- · 2019-03-07 04:43

After you hook up the UISwitch in Interface Builder, you can check if it's on like this:

-(IBAction) changeMode:(id)sender
{
     if ([(UISwitch *)sender on])
     {
          NSLog(@"The switch is on.");
     }
     else
     {
          NSLog(@"The switch is off.");
     }
}
查看更多
登录 后发表回答