Switch application


 

Switch application

In this application we are going to create it by using Window based application.

In this application we are going to create it by using Window based 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;

0

- (void)applicationDidFinishLaunching:(UIApplication *)application

{   

    [window makeKeyAndVisible];

1

}

-(void)switchAction:(id)sender

{

2

    if([mswitch isOn])

    {

        NSLog(@"Switch is ON");

3

    }

    else

    {

4

        NSLog(@"Switch is OFF");

    }

}

5

- (void)dealloc

{

    [window release];

6

    [super dealloc];

}

@end

7

 At last press Build And Go

Download code from here.

 

8

Ads