iphone - Save Text from UITableViews -


edit: found actual cause of crashing. needed delete , reinstall test without crashing altered data model. case of working out how correctly save array coredata. how can this?

i have uitableview , want able enter text cells save text in array, load text in array when load app.

im using coredata seem having issues. here have far.

in cellforrowatindex function adding uitextfields subview of each cell can type in them , can type in them when uiswitch, editcells, on. 4 of cells have preset text in them have set.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"cell";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease];     }      uitextfield *textfield = [[uitextfield alloc] initwithframe:cgrectmake(15, 20, 185, 30)];     textfield.delegate = self;      // configure cell...      if ([indexpath row] == 0) {         [cell setaccessoryview:textfield];         textfield.text = @"before school";         textfield.font = [uifont fontwithname:@"helvetica-oblique" size:16];         textfield.enabled = false;     }      else if ([indexpath row] == 3) {         [cell setaccessoryview:textfield];         textfield.text = @"break time";         textfield.font = [uifont fontwithname:@"helvetica-oblique" size:16];         textfield.enabled = false;     }      else if ([indexpath row] == 6) {         [cell setaccessoryview:textfield];         textfield.text = @"lunchtime";         textfield.font = [uifont fontwithname:@"helvetica-oblique" size:16];         textfield.enabled = false;     }      else if ([indexpath row] == 9) {         [cell setaccessoryview:textfield];         textfield.text = @"after school";         textfield.font = [uifont fontwithname:@"helvetica-oblique" size:16];         textfield.enabled = false;     }      else if ([indexpath row] == 1 || [indexpath row] == 2 || [indexpath row] == 4 || [indexpath row] == 5 || [indexpath row] == 7 || [indexpath row] == 8) {         [cell setaccessoryview:textfield];         textfield.font = [uifont fontwithname:@"helvetica" size:16];         if (editcells.on == true) {             textfield.enabled = true;         }         else {             textfield.enabled = false;         }     }      [monarraya addobject:textfield.text];      [textfield release];      return cell; } 

to save run when value of editcells changes, when user has finished editing saved switched turned off. make new object save core data. save lesson array cell text in , table needs in, saving tag. of course, chucks sigabrt error , crashes app when flicking switch.

[editcells addtarget:self action:@selector(editcells:) forcontrolevents:uicontroleventvaluechanged];  -(void)editcells:(id)sender{     [montable reloaddata];      //create new object save.     nsmanagedobject *newlesson;     //tell saved datedtext entity using managedobjectcontext, context_.     newlesson = [nsentitydescription insertnewobjectforentityforname:@"timetable" inmanagedobjectcontext:self.managedobjectcontext];     //set 2 values within object, being text user entered , date datepicker.     //save these appropriate properties within entity.     [newlesson setvalue:monarraya forkey:@"lessonname"];     [newlesson setvalue:montable.tag forkey:@"table"];      //create error incase of failure save.     nserror *saveerror = nil;     //try , access data store via context_ , fall on saveerror if fails.     [self.managedobjectcontext save:&saveerror];     if (saveerror != nil) {         //report error printing console.         nslog(@"[%@ savecontext] error saving context: error = %@, details = %@",[self class], saveerror,saveerror.userinfo);     } } 

tableviews work little differently you're expecting. important thing remember tableview:cellforrowatindexpath: called both create cell, , reuse one. should create subviews (like textfield) in if (cell == nil) path. make sure give each field unique tag , add them subviews of cell.

then, in configure cell path (after potentially creating elements) fields again calling [cell.contentview viewwithtag:your_field_tag] , update field.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -