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