objective c - UIPicker view problems -
ok lets try 1 more time, have picker in app , working fine code here
_fuglar = [[nsarray alloc]initwithobjects:@"allt árið", @"hrafn", @"svartbakur",@"silfurmáfur",@"sílamáfur",@"frá 20.ágúst til 15.mars",@"grágæs",@"heiðagæs",@"frá 1.september til 15.mars",@"fýll",@"dílaskarfur", nil]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - uipickerview methods - (nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview { return 1; } - (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { return _fuglar.count; } - (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component { return [_fuglar objectatindex:row]; } - (void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { //create uiimage objects uiimage * uglaimage = [uiimage imagenamed:@"ugla1.jpg"]; uiimage * ravenimage = [uiimage imagenamed:@"raven.jpg"]; uiimage * svartbakurimage = [uiimage imagenamed:@"svartbakur2.jpg"];
then want centre text in picker , change colour , using code picker goes blank can see pictures, ideas?
- (uiview *)pickerview:(uipickerview *)pickerview viewforrow:(nsinteger)row forcomponent:(nsinteger)component reusingview:(uiview *)view { uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 300, 37)]; label.textalignment = nstextalignmentcenter; label.backgroundcolor = [uicolor clearcolor]; label.textcolor = [uicolor bluecolor]; return label;
when populating picker view, implement either titleforrow, or viewforrow, not both. implementing viewforrow, you're substituting view default label. fix problem, delete titleforrow method, , set text of label in viewforrow:
- (uiview *)pickerview:(uipickerview *)pickerview viewforrow:(nsinteger)row forcomponent:(nsinteger)component reusingview:(uiview *)view { uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 300, 37)]; label.textalignment = nstextalignmentcenter; label.backgroundcolor = [uicolor clearcolor]; if (row == 0 || row == 2) { label.textcolor = [uicolor bluecolor]; }else{ label.textcolor = [uicolor blackcolor]; } label.text = [_fuglar objectatindex:row]; return label; }
Comments
Post a Comment