Share on Google+Share on Google+

Switch application

Advertisement
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;

- (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

Download code from here.

 

Advertisements

Advertisement

Posted on: August 25, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.