iphone - How can I set identity to each cell in UITableView? -


i have grouped uitable view custom setting view. each cell view 3 uitextfields , other uiviews.

when cell created call function

[cell initcell:indexpath.section withrow:indexpath.row]; 

and cell knows configuration display - works fine.

my problem when table scrolled cell looses it's identity causing save wrong settings. saved nsstring* view; nsstring* row;

but have last value, of last cell presented (became sidplayed)

maybe have missunderstanding global parameters, or maybe cell reuse. please advise, thanks

my cellforrowatindexpath:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {  if(indexpath.section==0) {     static nsstring *cellidentifierdate = @"settingscellpickdate";      settingscellpickdate *cell = (settingscellpickdate *)[tableview dequeuereusablecellwithidentifier:cellidentifierdate];     if (cell == nil) {         nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:cellidentifierdate owner:self options:nil];          for(id currentobject in toplevelobjects) {             if ([currentobject iskindofclass:[settingscellpickdate class]])              {                 cell = (settingscellpickdate *) currentobject;                 break;             }         }     }      [cell initcell:indexpath.section withrow:indexpath.row];     cell.selectionstyle = uitableviewcellselectionstylenone;        cell.frame = cgrectzero;      return cell; }   //tableview.rowheight = 100;     static nsstring *cellidentifierdate = @"settingscellvalue";  settingscellvalue *cell = (settingscellvalue *)[tableview dequeuereusablecellwithidentifier:cellidentifierdate]; if (cell == nil) {     nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:cellidentifierdate owner:self options:nil];      for(id currentobject in toplevelobjects) {         if ([currentobject iskindofclass:[settingscellvalue class]])          {             cell = (settingscellvalue *) currentobject;             break;         }     } }  [cell initcell:indexpath.section withrow:indexpath.row]; cell.selectionstyle = uitableviewcellselectionstylenone;  cell.frame = cgrectzero;  return cell;  } 

for example, settingscellvalue class looks (i change texts , removed stuff suggest app idea):

#import "settingscellvalue.h"  @implementation settingscellvalue @synthesize deflabel1, deflabel2, deflabel3, deflabel4, text1, text2, text3, typeofbar;  //@synthesize deflabel, valuefield;  - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {     if ((self = [super initwithstyle:style reuseidentifier:reuseidentifier])) {         // initialization code     }      return self; }  nsstring *view; nsstring *bar;  -(void) initcell:(int)section withrow:(int)row {     nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults];     nsinteger viewtype = [defaults integerforkey:@"screentype"];       bar = [self getbarastext:section];     view = [self getviewtypeastext:viewtype];      //update row 1     deflabel1.text = @"text1";     text1.text = [defaults objectforkey:[nsstring stringwithformat:@"%@/%@/caption", view, bar]];     //update row 2     deflabel2.text = @"text2";     typeofbar.selectedsegmentindex = [defaults integerforkey:[nsstring stringwithformat:@"%@/%@/type", view, bar]]; }  - (nsstring *) getbarastext:(int)section {     switch (section) {         case 1:             return @"ba1r";             break;         case 2:             return @"bar2";             break;         case 3:             return @"bar3";             break;         default:             return @"ba1r";             break;     } }  - (nsstring *) getviewtypeastext:(int)viewtype {     switch (viewtype) {         case 1:             return @"viewtype1";             break;             case 2:                 return @"viewtype2";                 break;             case 3:                 return @"viewtype3";                 break;             case 4:                 return @"viewtype4";                 break;         default:             return @"viewtype1";             break;     } }  -(ibaction) editingdidended:(id) sender {     nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults];      if (sender == text1) {         [defaults setobject:text1.text forkey:[nsstring stringwithformat:@"%@/%@/caption", view, bar]];     }       [defaults synchronize]; }  - (void)dealloc {     [ deflabel1, deflabel2, deflabel3, deflabel4, text1, text2, text3, typeofbar release];     [super dealloc]; }   @end 

you shouldn't tie data-object cell-object, break cell-reuse. while code doesn't totally wrong, question's title points in direction, haven't understood yet.

one thing noticed: use static nsstring *cellidentifierdate twice. should rename one.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

c# - How to execute a particular part of code asynchronously in a class -

c# - Asterisk click to call -