iphone - Add a row to a TableView from a Detail view -


so have tableview , detail view. have row in tableview "add" record. when click on new button send nil object detail view same use editing existing row. use following code that:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     new = no;     nsuinteger row = [indexpath row];     savedcardetailcontroller *detailcontroller = [[savedcardetailcontroller alloc] initwithnibname:@"savedcardetailcontroller" bundle:nil];     if(indexpath.row >= [listofcars count]){          nslog(@"new car");          detailcontroller.car = nil;         new = yes;     } else {         new = no;         detailcontroller.car = [listofcars objectatindex:row];     }     detailcontroller.managedobjectcontext = self.managedobjectcontext;     [self.navigationcontroller pushviewcontroller:detailcontroller animated:yes];     [detailcontroller release]; } 

when save core data stuff execute in detailcontroller

 - (void)viewwilldisappear:(bool)animated {     nserror * e = nil;     if(self.new){         nslog(@"new car saving");         nsmanagedobject * obj = [nsentitydescription insertnewobjectforentityforname:@"cars" inmanagedobjectcontext: managedobjectcontext];         [obj setvalue:name.text forkey:@"name"];         [obj setvalue:year.text forkey:@"year"];         [obj setvalue:notes.text forkey:@"notes"];      } else {         nslog(@"updating exiting car");         car.name = name.text;         car.year = year.text;         car.notes = notes.text; }     [managedobjectcontext save:&e];     if(e){         nslog(@"error occurred, %@", e);     }     if(self.new){      } else {     //  [self.parentviewcontroller.tableview reloaddata];      }  } 

then update tableview reloaddata updates modified feild

- (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];      if(new){         nsinteger row = [listofcars count];         nslog(@" row  %i", row);         nsarray *paths = [nsarray arraywithobject:[nsindexpath indexpathforrow:row insection:0]];         //nsarray * foo = [nsarray arraywitharray:<#(nsarray *)array#>         [self.tableview beginupdates];         [self.tableview insertrowsatindexpaths:paths withrowanimation:uitableviewrowanimationfade];         [self.tableview endupdates];         new = no;     }     //this works "changed data" not new rows.     [self.tableview reloaddata];   } 

this saves new rows database new row never appears. insertrows coredumps on me. pretty sure need use insertrowsatindexpaths have no clue put executed once have added object coredata. ideas?

you forget insert newly created car listofcars array.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -