A picker is a common control.
You need to reference two protocols before using the picker <UIPickerViewDataSource,UIPickerViewDelegate>
Also need to connect Datesource & Delegate
After calling the protocol, you need to override three methods
-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview This method returns the number of pickers.
-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) component This method returns a string of values for any picker
{
if (component==0)
{
return array_1.count;
}
Else
{
return array_2.count;
}
}
-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) Component This method returns the number of any number of strings
{
if (component==0)
{
return array_1.count;
}
Else
{
return array_2.count;
}
}
-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) component
{
if (component==0)
{
NSString *select=[self.array_1 Objectatindex:row];
Self.array_2=[self.date Objectforkey:select];
[Self.picker reloadcomponent:1]; Reloadcomponet method can refresh the picker again
}
}
Data from the picker can be removed from the P li s t file.
Select an array
Select an array type.
NSBundle * Bundle=[nsbundle mainbundle];//get a bundle;
NSString * Plistpath=[bundle pathforresource:@ "List" oftype:@ "plist"];//Get Path
Nsdictionary *dic=[[nsdictionary alloc]initwithcontentsoffile:plistpath]; Get to a dictionary by path
Self.date=dic;
Nsarray *array=[self.date AllKeys]; Get all Keys
Nsarray *sorted=[array sortedarrayusingselector: @selector (compare:)];
self.array_1=sorted;
NSString *select_1=[self.array_1 objectatindex:0]; Gets the first segment of the character
Nsarray *col2=[self.date objectforkey:select_1];
Self.array_2=col2;
Put the data in the plist file into a dictionary. The picker is then assigned a value through a dictionary.
IOS Picker Control