How to set UISegmented control in middle of the UINavigation Controller
1. For creating this app you may create first navigation controller application by using code and set title of the UINavigation
controller as a UISegmented controller.
2. Create project and select window-base template and you have to create your layout file which will show you alphabet
drag one label like above you can adjust your screen layout set hight and width of your layout.
3. Now open your SegmentedControlAppDelegate.h file and modify it as above If you select window-base application than
no need to modify it.
#import <UIKit/UIKit.h>
@interface SegmentedControlAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow * window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
4. Now you have to modify method applicationDidFinishLaunching method in your SegmentedControlAppDelegate.m file
for implementing UINavigation Controller.
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
UINavigationController * navController=[[UINavigationController alloc]initWithRootViewController:[[SegmentViewController
alloc]init]];
[window addSubview:navController.view];
[window makeKeyAndVisible];
}
5. Now right click on project and create new file and create subclass of UIViewController and give name of that file
SegmentViewController create .h and .m file and also select option of an .xib file.
6. After creating SegmentViewController all file and open SegmentViewController.h file and modify that file as
given below code in that file we have define one IBOutlet for UILabel to changeing the alphabet.
#import <UIKit/UIKit.h>
@interface SegmentViewController : UIViewController
{
IBOutlet UILabel * lable;
}
@property (nonatomic,retain)IBOutlet UILabel * lable;
@end
7. In above case we have define UILabel as a property so we have to first synthesize in SegmentViewController.m file
and modify viewDidLoad method property which we have synthesize we have to also provide deallocation of that property in
dealloc method of UIViewController class.
#import "SegmentViewController.h"
@implementation SegmentViewController
@synthesize lable;
- (void)viewDidLoad
{
self.view=[[[NSBundle mainBundle]loadNibNamed:@"SegmentViewController" owner:self options:nil]lastObject];
NSArray * buttonNames=[[NSArray alloc]initWithObjects:@"A",@"B",@"C",@"D",@"E", nil];
UISegmentedControl * segmentedControll=[[UISegmentedControl alloc]initWithItems:buttonNames];
segmentedControll.segmentedControl;
segmentedControll.selectedSegmentIndex=0;
segmentedControll.momentary=YES;
[segmentedControll addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView=segmentedControll;
[segmentedControll release];
}
//This method is used for when segment change alphabet
-(void)segmentAction:(UISegmentedControl *)sender
{
[self.lable setText:[NSString stringWithFormat:@"%0c",sender.selectedSegmentIndex+65]];
}
- (void)dealloc
{
[lable release];
[super dealloc];
}
@end
8. Now your project is completed and you can run on simulator by pressing command+r.
Releted Posts :
1. UIText Field with default and number pad keybord
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. Create simple UINavigation controller in iPhone
5. How to install Mac os x in windows PC
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. Create simple UINavigation controller in iPhone
5. How to install Mac os x in windows PC
HTML Comment Box is loading comments...