iOS Programming
Objective C + iOS
Profile
Ankit Desai
 Ph.D. Scholar, IET, Ahmedabad University
 Education: M. Tech. CE, B.E. I. T.
 Experience: 7.5 Years (Academic and Research)
 Research Interest: IoT, Big Data Analytics,
Machine Learning, Data Mining.
UIPickerView Control
 Drag a UIPickerView on xib
 Add delegates after class-name
<UIPickerViewDataSource,UIPickerViewDelegate>
 Declare two NSArray in .h file
 NSArray *arrItems;
 NSArray *arrLocation;
Initialize arrays in .m files
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
arrItems=[[NSArray
alloc]initWithObjects:@"iphone",@"android",@"java",@"testing", nil];
arrLocation=[[NSArray
alloc]initWithObjects:@"ahmedabad",@"baroda",@"surat", nil];
}
Add delegates methods 1 & 2
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{ return 2; }
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (component==0) {
return [arrItems count];
}
else {
return [arrLocation count];
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (component==0) {
return [arrItems objectAtIndex:row];
}
else {
return [arrLocation objectAtIndex:row];
}
}
Add delegates methods 3
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *Str;
if (component==0) {
Str =[arrItems objectAtIndex:row];
}
else{
Str = [arrLocation objectAtIndex:row];
}
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"selected" message:Str
delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
Add delegates methods 4
Output
Thank you
 For further communication or queries:
 Contact me:
 desaiankitb@gmail.com
 www.fb.com/desaiankitb

Presentation5 picker view

  • 1.
  • 2.
    Profile Ankit Desai  Ph.D.Scholar, IET, Ahmedabad University  Education: M. Tech. CE, B.E. I. T.  Experience: 7.5 Years (Academic and Research)  Research Interest: IoT, Big Data Analytics, Machine Learning, Data Mining.
  • 3.
    UIPickerView Control  Draga UIPickerView on xib  Add delegates after class-name <UIPickerViewDataSource,UIPickerViewDelegate>  Declare two NSArray in .h file  NSArray *arrItems;  NSArray *arrLocation;
  • 4.
    Initialize arrays in.m files - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. arrItems=[[NSArray alloc]initWithObjects:@"iphone",@"android",@"java",@"testing", nil]; arrLocation=[[NSArray alloc]initWithObjects:@"ahmedabad",@"baroda",@"surat", nil]; }
  • 5.
    Add delegates methods1 & 2 // returns the number of 'columns' to display. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 2; } // returns the # of rows in each component.. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if (component==0) { return [arrItems count]; } else { return [arrLocation count]; } }
  • 6.
    - (NSString *)pickerView:(UIPickerView*)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if (component==0) { return [arrItems objectAtIndex:row]; } else { return [arrLocation objectAtIndex:row]; } } Add delegates methods 3
  • 7.
    - (void)pickerView:(UIPickerView *)pickerViewdidSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSString *Str; if (component==0) { Str =[arrItems objectAtIndex:row]; } else{ Str = [arrLocation objectAtIndex:row]; } UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"selected" message:Str delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; [alert show]; } Add delegates methods 4
  • 8.
  • 9.
    Thank you  Forfurther communication or queries:  Contact me:  desaiankitb@gmail.com  www.fb.com/desaiankitb