IOS Picker Control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.