uipickerview - Custom Picker View for iOS 6.1 -
i trying setup simple custom picker view has 2 components based on arrays. first array (used in component 0) defined as:
onesscore = [[nsmutablearray alloc]init]; [onesscore addobject:@"5"]; [onesscore addobject:@"6"]; [onesscore addobject:@"7"]; [onesscore addobject:@"8"]; [onesscore addobject:@"9"];
the second array (used in component 1) defined as:
tenthsscore = [[nsmutablearray alloc]init]; [tenthsscore addobject:@"0"]; [tenthsscore addobject:@"1"]; [tenthsscore addobject:@"2"]; [tenthsscore addobject:@"3"]; [tenthsscore addobject:@"4"]; [tenthsscore addobject:@"5"]; [tenthsscore addobject:@"6"]; [tenthsscore addobject:@"7"]; [tenthsscore addobject:@"8"]; [tenthsscore addobject:@"9"];
the using following code create custom view:
- (uiview *)pickerview:(uipickerview *)picker viewforrow:(nsinteger)row forcomponent:(nsinteger)component reusingview:(uiview *)view{ uilabel* retval = (id)view; if (!retval){ retval= [[uilabel alloc] initwithframe:cgrectmake(0.0f, 0.0f, [picker rowsizeforcomponent:component].width, [picker rowsizeforcomponent:component].height)]; if (component == 0) { retval.text = [onesscore objectatindex:row]; } else if (component == 1) { retval.text = [tenthsscore objectatindex:row]; } retval.font = [uifont fontwithname:@"helvetica" size:48]; retval.backgroundcolor =[uicolor clearcolor]; retval.textalignment = nstextalignmentcenter; } return retval; }
the ui of picker works great , first component loads correctly, issue second component get:
0, 1, 2, 3, 4, 5, 0, 1, 2, 3
it's not loading full "tenthsscore" array properly. i'm @ complete loss.
any ideas?
in future, please make effort format code properly. doing makes easier you.
anyway, you're setting label's text
when you're first creating label. in case when you're reusing label, return reused label unchanged.
- (uiview *)pickerview:(uipickerview *)picker viewforrow:(nsinteger)row forcomponent:(nsinteger)component reusingview:(uiview *)view { uilabel* retval = (id)view; if (!retval){ retval= [[uilabel alloc] initwithframe:cgrectmake(0.0f, 0.0f, [picker rowsizeforcomponent:component].width, [picker rowsizeforcomponent:component].height)]; retval.font = [uifont fontwithname:@"helvetica" size:48]; retval.backgroundcolor =[uicolor clearcolor]; retval.textalignment = nstextalignmentcenter; } if (component == 0) { retval.text = [onesscore objectatindex:row]; } else if (component == 1) { retval.text = [tenthsscore objectatindex:row]; } return retval; }
Comments
Post a Comment