UISegmented control in iPhone with value change event
1. For UISegmented Control you have require View-Base Application so first Create View-Base Application and give name Segment in Xcode and drag one UISegmented and UILabel from liberary in your SegmentViewController.xib file .
2. Now Define IBOutlet for UILabel and UIAction for UIButton as follow.
#import <UIKit/UIKit.h>
@interface SegmentViewController : UIViewController
{
IBOutlet UILabel * segment;
}
-(IBAction)handleSegment:(id)sender;
@end
3. Open SegmentViewConroller.xib file and set your outlet to UILabel and UIButton touch up inside event to UIButton and
open SegmentViewController.m file and modify as follow.
#import "SegmentViewController.h"
@implementation SegmentViewController
-(IBAction)handleSegment:(id)sender
{
UISegmentedControl * mySegment=(UISegmentedControl *)sender;
if(mySegment.selectedSegmentIndex==0)
{
segment.text=@"First Segment";
}
else if(mySegment.selectedSegmentIndex==1)
{
segment.text=@"Second Segment";
}
else
{
segment.text=@"Third Segment";
}
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations return
(interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
3. Now you can test your application in simulator.
#import <UIKit/UIKit.h>
@interface SegmentViewController : UIViewController
{
IBOutlet UILabel * segment;
}
-(IBAction)handleSegment:(id)sender;
@end
3. Open SegmentViewConroller.xib file and set your outlet to UILabel and UIButton touch up inside event to UIButton and
open SegmentViewController.m file and modify as follow.
#import "SegmentViewController.h"
@implementation SegmentViewController
-(IBAction)handleSegment:(id)sender
{
UISegmentedControl * mySegment=(UISegmentedControl *)sender;
if(mySegment.selectedSegmentIndex==0)
{
segment.text=@"First Segment";
}
else if(mySegment.selectedSegmentIndex==1)
{
segment.text=@"Second Segment";
}
else
{
segment.text=@"Third Segment";
}
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations return
(interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
3. Now you can test your application in simulator.
Releted Posts :
1. UIText Field with default and number pad keybord
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. UISegmented control in iPhone with value change event
5. Create simple UINavigation controller in iPhone
6. How to install mac os x on windows pc
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. UISegmented control in iPhone with value change event
5. Create simple UINavigation controller in iPhone
6. How to install mac os x on windows pc
HTML Comment Box is loading comments...