谁能告诉我如何使用开关?

时间:2011-04-12 17:40:03

标签: cocoa-touch ios button switch-statement

  

可能重复:
  How to apply setting by toggle switch?

我想使用开关按钮来打开和关闭设置

谁能告诉我如何设置它?我已经有以下代码

谢谢!

声明

- (IBAction) changeMode:(id)sender;

实施

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

1 个答案:

答案 0 :(得分:3)

在Interface Builder中连接UISwitch后,您可以检查它是否打开:

-(IBAction) changeMode:(id)sender
{
     if ([(UISwitch *)sender on])
     {
          NSLog(@"The switch is on.");
     }
     else
     {
          NSLog(@"The switch is off.");
     }
}