.h文件中声明:
UISwitch * leftSwitch;
@property (nonatomic , retain) IBOutlet UISwitch * leftSwitch;
.m文件中添加:
@synthesize leftSwitch;
viewDidUnload()中添加:
leftSwitch = nil;
dealloc()中添加:
[leftSwitch release];
显示:
leftSwitch.hidden = NO;
隐藏:
leftSwitch.hidden = YES;
通过IBAction方法设置开关
-(IBAction) switchChanged:(id)sender
{
UISwitch * whichSwitch = (UISwitch *)sender;
BOOL setting = whichSwitch.isOn;
[leftSwitch setOn:setting animated:YES];
[rightSwitch setOn:setting animated:YES];
}
本文详细介绍了在iOS应用开发中如何使用UISwitch组件。包括在.h文件中声明属性,在.m文件中合成属性,并展示了如何在代码中显示和隐藏开关。此外,还提供了通过IBAction方法改变开关状态的具体实现。

6667

被折叠的 条评论
为什么被折叠?



