BOOL 変数 = [《UISwitch*》 isOn];このisOnメソッドで、スイッチがONならばYES、OFFならばNOが取得できます。また、逆に値を変更するためのメソッドとしてsetOn:というものも用意されています。
[《UISwitch*》 setOn:《BOOL》];これも引数でYESを指定すればONに、NOならばOFFに設定変更されます。非常に簡単なメソッドですので、改めて説明の必要もないでしょう。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※MyIAppViewController.h #import <UIKit/UIKit.h> @interface MyIAppViewController : UIViewController { UILabel * label1; UISwitch * switch1; } @property (nonatomic, retain) IBOutlet UILabel *label1; @property (nonatomic, retain) IBOutlet UISwitch * switch1; - (IBAction)switch1Action:(id)sender; @end ※MyIAppViewController.m #import "MyIAppViewController.h" @implementation MyIAppViewController @dynamic label1; @dynamic switch1; @dynamic slider1; @dynamic segment1; - (IBAction)switch1Action:(id)sender { BOOL swth = [switch1 isOn]; NSString* swstr = swth ? @"YES" : @"NO"; NSString* msg = [NSString stringWithFormat:@"Switch: %@",swstr]; [label1 setText:msg]; } ……中略…… @end
次へ >> |