首先在.h 檔 做以下宣告
UIWindow *window;
UILabel *display;
//產生一個 switch object
UISwitch *switchchange;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property(nonatomic,retain)IBOutlet UISwitch *switchchange;
@property(nonatomic,retain)IBOutlet UILabel *display;
-(IBAction)switchchanged:(id)sender;
@end
"
@synthesize window;
@synthesize switchchange;
@synthesize display;
//這邊控制按鈕的動作
-(IBAction)switchchanged:(id)sender
{
UISwitch *whichswitch=(UISwitch *)sender;
//當按鈕移動到ON 就印出test的字串
if (whichswitch.isOn==YES) {
display.text=@"test";
}
//當移動到Off 就印出test2
else
display.text=@"test2";
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
沒有留言:
張貼留言