Home Tutorial Iphone Examples Switch application

 
 

Share on Google+Share on Google+
Switch application
Posted on: August 25, 2009 at 12:00 AM
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.

 

Advertisement

Related Tags for Switch application :


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.

Posted on: August 25, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com