How to make piker view or dropdown list in iphone using programming??

Leave a Comment
Make piker view to create dropdown list in phone. Here select country name and that will be displayed on label. This is very simple basic application for uipikerview. Header and implementation files are below.

devangViewController .h

#import <UIKit/UIKit.h>
@interface devangViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *lbl;

@property (strong, nonatomic) NSArray *countryNames;
@property (strong, nonatomic) NSArray *exchangeRates;
@end
devangViewController .m

#import "devangViewController.h"
@interface devangViewController ()
@end
@implementation devangViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
   
    _countryNames = @[@"Australia (AUD)", @"China (CNY)",
                      @"France (EUR)", @"Great Britain (GBP)", @"Japan (JPY)"];
   
 
}
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    return _countryNames.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component
{
    return _countryNames[row];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
      inComponent:(NSInteger)component
{
   
       
    NSString *resultString = [[NSString alloc] initWithFormat:
                              @"%@",
                              _countryNames[row]];
    _lbl.text = resultString;
}
@end
Output:

0 comments:

Post a Comment