Blog

iPhone - UI Picker view

  • (4.0)
  • | 1157 Ratings

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 offerst 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
 

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


Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.

Ravindra Savaram
About The Author

Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.


DMCA.com Protection Status

Close
Close