Home  >  Blog  >   iPhone  > 

iPhone - UI Picker view

Rating: 4
  
 
2148

 

Picker view

A PICKER VIEW lets the user choose between certain options by spinning a wheel on the screen. Picker views are well suited for choosing things like dates and times (as the date picker does) that have a moderate number of discrete options. Pickers consist of a rotating scrollable view, which is used for picking a value from the list of items.
 

Looking for IOS Development Training? Mindmajix offers the industry best online training with experts.

 

.h file:-

 
 # import   
 @ interface   divpickerviewController  :   UIviewController
 {
 NsMutableArray      * aArray;
 }
@ end
 

.m file:-

 
# import  “ divpickerview  viewController .h”
@ implementation   divPickerview   viewController
-(void)    viewDidLoad
{
a Array  =   [[ NSMutableArray   alloc]  initWithObjects:
@ “one”, @ “two”, @ “three”, @ “four”, @ “five”, nil];
[ super   viewDidLoad];
}
 

# Program Mark Pickerview Data Source:

 
Capture 15
 
-( NSInteger)  numberOfComponentsInpicker view:
( UIPicker view    :)  pickerview
{
Return   4;
}
 
Capture 15
 
-(NSInteger)  pickerview:  (  UIpicker view     *)   pickerview
NumberofRowsInComponent:  ( NSInteger)Component
{
Return  [     aArray   Count];
}
 
Capture 15
 
-(NSString       *)  pickerview   :   (UIPickerview     *)    pickerview
titleForRow: ( NSInteger)   row  forComponent:
(NSInteger )Component;
{
return  [aArray  objectAtIndex   :  row];
}
 
 
Capture 15
 
-(void)   picker view :  (UIpicker view     *)   pickerview
didSelectRow:  ( NSInteger)  row  in ComponenT :
(NSInteger)Component
{
NSLog   (   @ “ didSelectRow is called  and  row  is %d  and  component  is %d”,   row  Component);
}
 
Output:-
one
 
one
 
one
 
one
two two two two
Three Three Three Three
Four Four Four Four
Five Five Five Five

MindMajix Youtube Channel

Data Picker View:

. h file:

# import   
@ interface    divdatepickerviewController: UIViewController
{
IBoutlet       UIDatePicker    * Datepicker;
}
-(   IBAction)   dateChanged;
@ end
 

.m file:-

 
# import “ divdatepickerviewController. h”
@  implementation   divdatepickerviewController
-(IB action) dateChanged
{
NSDate       *  date   =    [   datepicker   date];
NSLog   (   @   “date  is %@”, date);
}
 
 Fri Jul.15  2  55  
 Sat Jul.16  3  00  AM
 Today  4  05  PM
 Mon Jul18  5  10  
 Tue Jul19  6  15  

Image picker view:-

.h file:-

 
# import   
@ interface   b8  ImagePickerviewController :  UIviewController
 
< UINavigationControllerDelegate, UIImagePicker Controller  Delegate>
{
}
-(IBAction)  buttonClicked;
@ end
 

.m  file:-

# import  “b8ImagePickerviewController. h”
@ implementation b8ImagepickerviewController
-(IBAction)  buttonClicked
{
UIImagePickerController     * picker  =    [[ UIImagepickerController alloc]  init];
[Picker  SetSourceType: UIImagePickerControllerSourceTypephoto Library];
[picker  setDelegate  :  self];
Picker . editing  =   YES;
[self PresentModelViewController: picker  animated  : YES];
}
-(void) imagePickerController  : (UIImagePickerController    *)
Picker  didFinishPickingMedia withInfo:
(NSDictionary    *) info
{
NSLog  ( @ “editing info   is %@”,  info);
UIImage    * image  = [info  objectForkey: @ “UIImagePicker ControllerOriginalImage”];
Self. view  .backgroundColor  = [UI color  Colorwithpattern Image : image];
[ picker dismissModelviewControllerAnimated  : YES”];
}
-(void) imagepickerControllerDidCancel : ( UIImagePickerController    *) picker
{
[ self dismiss model viewControllerAnimated  : YES];
}

 

Frequently Asked iPhone Interview Questions & Answers

 

Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
IOS Development TrainingMay 23 to Jun 07
IOS Development TrainingMay 28 to Jun 12
IOS Development TrainingMay 30 to Jun 14
IOS Development TrainingJun 04 to Jun 19
Last updated: 08 Apr 2022
About Author
Ruchitha Geebu

I am Ruchitha, working as a content writer for MindMajix technologies. My writings focus on the latest technical software, tutorials, and innovations. I am also into research about AI and Neuromarketing. I am a media post-graduate from BCU – Birmingham, UK. Before, my writings focused on business articles on digital marketing and social media. You can connect with me on LinkedIn.

Recommended Courses

1 /15