objective c - textfield text leaves an impression on other textfiled when tableview is scrolled -
hi guys have custom tableview cells called product cell,rating cell,notify cell,where product cell contains textfield used in section 0,1,2,4. problem if input text in textfileds present in section 0. when scrolled ve left text impressions on textfileds present in section1,2..could u guys me out.below code
-(productcell *)getproductcell { nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"productcell" owner:nil options:nil]; productcell *cell; (id currentobject in toplevelobjects) { if ([currentobject iskindofclass:[productcell class]]) { cell= (productcell*)currentobject; return cell; } } return nil; } -(ratingcell *)getratingcell { nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"ratingcell" owner:nil options:nil]; ratingcell *cell; (id currentobject in toplevelobjects) { if ([currentobject iskindofclass:[ratingcell class]]) { cell= (ratingcell*)currentobject; return cell; } } return nil; } -(notifycell *)getnotifycell { nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"notifycell" owner:nil options:nil]; notifycell *cell; (id currentobject in toplevelobjects) { if ([currentobject iskindofclass:[notifycell class]]) { cell= (notifycell *)currentobject; return cell; } } return nil; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier1 = @"cell1"; static nsstring *cellidentifier2 = @"cell2"; static nsstring *cellidentifier3 = @"cell3"; productcell *productcell; notifycell *notifycell; productcell=(productcell *)[tbladdproducts dequeuereusablecellwithidentifier:cellidentifier1]; notifycell = (notifycell*)[tbladdproducts dequeuereusablecellwithidentifier:cellidentifier2]; uinib * nib1 = [uinib nibwithnibname:@"productcell" bundle: nil]; [tableview registernib:nib1 forcellreuseidentifier:cellidentifier1]; uinib * nib2 = [uinib nibwithnibname:@"notifycell" bundle: nil]; [tableview registernib:nib2 forcellreuseidentifier:cellidentifier2]; uinib * nib3 = [uinib nibwithnibname:@"ratingcell" bundle: nil]; [tableview registernib:nib3 forcellreuseidentifier:cellidentifier3]; if (notifycell == nil) { notifycell = [self getnotifycell]; } if (ratingcell == nil) { ratingcell = [self getratingcell]; } if (productcell == nil) { productcell = [self getproductcell]; } productcell.txtfield.delegate=self; productcell.selectionstyle = uitableviewcellselectionstylenone; notifycell.selectionstyle = uitableviewcellselectionstylenone; ratingcell.selectionstyle = uitableviewcellselectionstylenone; switch (indexpath.section) { case 0: productcell.lblname.text=[producttitlearray objectatindex:indexpath.row]; productcell.txtfield.tag=indexpath.row; if([productcell.lblname.text isequaltostring:@"valid till"]) productcell.txtfield.returnkeytype = uireturnkeydone; else productcell.txtfield.returnkeytype = uireturnkeynext; cellsection = indexpath.section; return productcell; break; case 1: productcell.lblname.text=[invoicetitlearray objectatindex:indexpath.row]; productcell.txtfield.tag=indexpath.row; if ([productcell.lblname.text isequaltostring:@"bank name"]) productcell.txtfield.returnkeytype = uireturnkeydone; else productcell.txtfield.returnkeytype = uireturnkeynext; cellsection = indexpath.section; return productcell; break; case 2: productcell.lblname.text=[warrantytitlearray objectatindex:indexpath.row]; productcell.txtfield.tag=indexpath.row; if ([productcell.lblname.text isequaltostring:@"valid till"]) productcell.txtfield.returnkeytype = uireturnkeydone; else productcell.txtfield.returnkeytype = uireturnkeynext; cellsection = indexpath.section; return productcell; break; case 3: productcell.lblname.text=@"description"; productcell.txtfield.tag=indexpath.row; if ([productcell.lblname.text isequaltostring:@"description"]) productcell.txtfield.returnkeytype = uireturnkeydone; cellsection = indexpath.section; return productcell; break; case 4: ratingcell.lblname.text=@"rating"; ratingcell.starratingcontrol.delegate=self; cellsection = indexpath.section; return ratingcell; break; case 5: productcell.lblname.text=[servicecontactstitlearray objectatindex:indexpath.row]; productcell.txtfield.tag=indexpath.row; if ([productcell.lblname.text isequaltostring:@"email"]) productcell.txtfield.returnkeytype = uireturnkeydone; else productcell.txtfield.returnkeytype = uireturnkeynext; cellsection = indexpath.section; return productcell; break; case 6: notifycell.lblname.text=[notifytitlearray objectatindex:indexpath.row]; cellsection = indexpath.section; return notifycell; break; default: break; } productcell.selectionstyle = uitableviewcellselectionstylenone; return productcell; }
your table view cells being reused. way table view cells being optimized.
if know how many sections , rows table view has , not change, consider using static table view cells suitable forms:
look @ section the technique static row content.
otherwise need save value of each text field variable, such rating, email, description, , put text field every time respective table view cell loaded.
Comments
Post a Comment