iOS Development Diary 48-detailed Uipickerview

Source: Internet
Author: User
Tags uicontrol

Today Bo Master has a uipickerview demand, met some difficulties, here and we share, hope to progress together.

Uipickerview is a selector control that is more generic than uidatepicker, it can generate a single-column selector, can also generate multiple columns of selectors, and developers can completely customize the appearance of the selection, so the use is very flexible.

Uipickerview directly inherits the UIView, does not inherit Uicontrol, so it cannot bind an event-handling method like Uicontrol, and the Uipickerview event processing is done by its delegate object.

Self.viewofpick=[[uipickerview alloc]initwithframe:cgrectmake (0, Max, [UIScreen mainscreen].bounds.size.height )];

_viewofpick.datasource=self;

_viewofpick.delegate=self;

Pickerview default to row 0, wireless scrolling only displays the middle value of the row at the beginning, causing the illusion of wireless scrolling

[_viewofpick selectrow:9 incomponent:0 Animated:yes];

Set Pickerview the last line is selected by default

[_viewofpick selectrow:9 incomponent:1 Animated:yes];

[Self.view Addsubview:_viewofpick];

Cell for row similar to TableView, based on row and component return string display

-(Nullable NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) Component __tvos_prohibited

{

return @ "EMPTY";

}

Similar to TableView Didselect, according to row and component to carry out the specific operation of the value, etc.

-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (nsinteger) component __tvos_ Prohibited

{

NSLog (@ "*********%ld,%ld", (long) component,row);

}

Cell for row similar to TableView, which returns a custom view display based on row and component

Note that both the return NSString and the following method of returning UIView are implemented, only the method that returns UIView is executed

-(UIView *) Pickerview: (Uipickerview *) Pickerview Viewforrow: (nsinteger) Row forcomponent: (Nsinteger) component Reusingview: (Nullable UIView *) View __tvos_prohibited

{

UIView *blackview=[[uiview alloc]initwithframe:cgrectmake (0, 0, 10, 10)];

Blackview.backgroundcolor=[uicolor Blackcolor];

return blackview;

}

Returns the row height of the Pickerview

-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: (nsinteger) component __tvos_prohibited

{

return 40;

}

Returns the number of ' columns ' to display.component

-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview

{

return 2;

}

Returns the # of rows in each component. Number of row

-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) component

{

return 10;

}

iOS Development Diary 48-detailed Uipickerview

Related Article

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.