2011年6月20日 星期一

Easy to use UISwitch

IBOutlet UISwitch --> value changed event
(UISlider也是類似此方式)
//
//  PowerBankViewController.h

@interface PPowerBankViewController : UIViewController {
IBOutlet UISwitch *aSwitch;
}


@property (nonatomic, retain) IBOutlet UISwitch *aSwitch;



-(IBAction)onSwitch:(id)sender;

//
//  PowerBankViewController.m
@synthesize aSwitch;
-(IBAction)onSwitch:(id)sender
{
aSwitch = (UISwitch *)sender;
NSLog(@"in onSwitch");
if ([aSwitch isOn] == YES) {
NSLog(@"[aSwitch isOn] == YES");
}
else{
NSLog(@"[aSwitch isOn] == NO");
}
}

- (void)viewDidLoad {
aSwitch = [[UISwitch alloc] init];
}

- (void)dealloc {
[aSwitch release];
    [super dealloc];
}







沒有留言:

張貼留言