iphone - UIPickerView in UITableViewCell:issue in showing the value at particular cell -
i using uipickerview in uitableview picking integer value. not getting how set value label in particular cell. below code:
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell; cell = [self.mtickettable dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } else{ cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } cell.backgroundview = [[uiimageview alloc]initwithimage:[uiimage imagenamed:@"cell.bg.png"]]; cell.selectionstyle = uitableviewcellselectionstylenone; lbltype = [[uilabel alloc]initwithframe:cgrectmake(10, 15, 90, 30)]; lblprice = [[uilabel alloc]initwithframe:cgrectmake(140, 15, 90, 30)]; lblseat = [[uilabel alloc]initwithframe:cgrectmake(232, 21, 52, 26)]; lblseat.text = strselected; lblseat.tag = indexpath.row+1; lblseat.textcolor = [uicolor lightgraycolor]; lblseat.textalignment = nstextalignmentcenter; lblseat.backgroundcolor = [uicolor clearcolor]; uibutton *btnpicker = [uibutton buttonwithtype:uibuttontypecustom]; [btnpicker setimage:[uiimage imagenamed:@"drop_down.png"] forstate:uicontrolstatenormal]; [btnpicker addtarget:self action:@selector(pickseats:) forcontrolevents:uicontroleventtouchupinside]; btnpicker.frame = cgrectmake(232, 20, 80, 30); self.mpickerview = [[uipickerview alloc] init]; self.mpickerview.frame = cgrectmake(228, 100, 90, 60); self.mpickerview.showsselectionindicator = yes; self.mpickerview.delegate = self; self.mpickerview.datasource = self; [self.mpickerview setneedslayout]; self.mpickerview.transform = cgaffinetransformmakescale(0.75f, 0.75f); self.mpickerview.hidden = true; [self.view addsubview:self.mpickerview]; lbltype.text = [arrtype objectatindex:indexpath.row]; if([arrcost count] == 0) { lblprice.text = @"0"; } else{ lblprice.text = [arrcost objectatindex:indexpath.row]; } [cell addsubview:lbltype]; [cell addsubview:lblprice]; [cell addsubview:btnpicker]; [cell addsubview:lblseat]; return cell; } -(nsinteger) numberofcomponentsinpickerview:(uipickerview *)pickerview { return 1; } -(nsinteger) pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { return 10; } -(nsstring *) pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component { return [numbers objectatindex:row]; } -(void) pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { strselected = [numbers objectatindex:row]; nslog(@"str selection:%@", strselected); self.mpickerview.hidden = true; [self.mtickettable reloaddata]; }
please guide above.
thanks in advance.
according me can :
first of assign tag btnpicker , lblseat like
btnpicker.tag = indexpath.row; lblseat.tag = 11111;
then in didselectrow method pickerview assign selected value array.
-(void) pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { int index = pickerview.tag; strselected = [numbers objectatindex:row]; nsindexpath *path = [nsindexpath indexpathforrow:index insection:0]; uitableviewcell *cell = [self.tableview cellforrowatindexpath:path]; (uiview* tempview in [cell subviews]) { if ([tempview iskindofclass:[uilabel class]]) { if (tempview.tag == 11111) { uilabel *lbltemp = (uilabel *)tempview; lbltemp.text = strselected; break; } } } self.mpickerview.hidden = true; }
replace pickseats method :
-(void)pickseats:(id)sender { uibutton *btn = (uibutton *) sender; self.mpickerview.tag = btn.tag; self.mpickerview.hidden = false; }
i think work. if not let me know. thnks.
Comments
Post a Comment