Switch application

In this application we are going to create it by using Window based application.
So we will find one window.
There is  .h and  .m file.
We are going to add Switch to Window.
Create a new project by selecting Window-Based Application.Open the Interface Builder by double clicking the MainWindow.xib file and add a Switch from the library.
  here we are declaring Switch as mswitch(its a variable) using UISwitch.It looks like this
IBOutlet UISwitch *mswitch;
  we are writing the action on button i.e.
(-(void)switchAction:(id)sender;)
   .h file will look like this:
  #import <UIKit/UIKit.h>
  @interface SwitchAppDelegate : NSObject <UIApplicationDelegate>
{
    UIWindow *window;
    IBOutlet UISwitch *mswitch;
}
  @property (nonatomic, retain) IBOutlet UIWindow *window;
 
-(void)switchAction:(id)sender;
@end
In this we are writing the method for switch
make connection in interface builder
 .m file will look like this:
import “SwitchAppDelegate.h”
@implementation SwitchAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{   
    [window makeKeyAndVisible];
}
-(void)switchAction:(id)sender
{
    if([mswitch isOn])
    {
        NSLog(@”Switch is ON”);
    }
    else
    {
        NSLog(@”Switch is OFF”);
    }
}
- (void)dealloc
{
    [window release];
    [super dealloc];
}
@end
 At last press Build And Go

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>