Ios 如何设置开机/关机状态?
我尝试使用Ios 如何设置开机/关机状态?,ios,uiswitch,Ios,Uiswitch,我尝试使用[self.switchAutoPlay setOn:YES]将开关设置为打开状态。但它不起作用。这就是我所做的 在界面中 @property (weak, nonatomic) IBOutlet UISwitch *switchAutoPlay; 正在实施中 [[self switchAutoPlay] setOn:YES]; 让我知道一种方法来实现这一点。最初检查,您是否连接了UISwitch 在视图中加载 switchAutoPlay.isOn --> is for
[self.switchAutoPlay setOn:YES]
将开关设置为打开状态。但它不起作用。这就是我所做的
在界面中
@property (weak, nonatomic) IBOutlet UISwitch *switchAutoPlay;
正在实施中
[[self switchAutoPlay] setOn:YES];
让我知道一种方法来实现这一点。最初检查,您是否连接了
UISwitch
在视图中加载
switchAutoPlay.isOn --> is for on
!switchAutoPlay.isOn --> is for off
方法
[switchAutoPlay addTarget: self action: @selector(flip:) forControlEvents: UIControlEventValueChanged];
方法
- (IBAction)flip:(id)sender{
if([sender isOn]){
NSLog(@"Switch is ON");
} else{
NSLog(@"Switch is OFF");
}
}
Choice-2
在developperAPI中可以看到,任务setOn:animated:
应该可以完成这个任务
- (void)setOn:(BOOL)on animated:(BOOL)animated
因此,要在程序中打开开关,您可以使用:
目标-C
[switchAutoPlay setOn:YES animated:YES];
你把插座接上了吗?你把插座接好了吗<代码>self.switchAutoPlay.on=是代码>应该可以工作。同时检查self.switchAutoPlay是否不是nil