iphone - Can't Seem To Fix This Basic Save/Fetch Request -


its been 3 weeks i've been seeking on site simple save/fetch feature using core data can't work. keep getting different suggestions people , change code accordingly can never working properly.

its discouraging taken me long simple error yet did 100x work in week prior hit. bummer when learning how program.

here scenario: tableview blank default until user inputs name string via + button in nav bar. string entered should add cell view name title. should saved memory , fetched upon relaunch of application.

the problem: following error @ line: cell.textlabel.text = [eventsarray objectatindex:indexpath.row];

in method of: - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

2011-04-11 22:40:49.824 curl[2244:207] -[routine isequaltostring:]: unrecognized selector sent instance 0x5c09ad0 2011-04-11 22:40:50.005 curl[2244:207] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[routine isequaltostring:]: unrecognized selector sent instance 0x5c09ad0' 

my data model:

enter image description here

viewcontroller code:

`@implementation routinetableviewcontroller  @synthesize tableview; @synthesize eventsarray; @synthesize entered; @synthesize managedobjectcontext;  #pragma mark - view lifecycle  - (void)viewdidload {     if (managedobjectcontext == nil)      {          managedobjectcontext = [(curlappdelegate *)[[uiapplication sharedapplication] delegate] managedobjectcontext];      }      nsfetchrequest *request = [[nsfetchrequest alloc] init];     nsentitydescription *entity = [nsentitydescription entityforname:@"routine" inmanagedobjectcontext:managedobjectcontext];     [request setentity:entity];      nserror *error = nil;     nsmutablearray *mutablefetchresults = [[managedobjectcontext executefetchrequest:request error:&error] mutablecopy];     if (mutablefetchresults == nil) {         // handle error.     }     [self seteventsarray:mutablefetchresults];     [mutablefetchresults release];     [request release];      uibarbuttonitem * addbutton = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self action:@selector(showprompt)];     [self.navigationitem setleftbarbuttonitem:addbutton];     [addbutton release];      uibarbuttonitem *editbutton = [[uibarbuttonitem alloc]initwithtitle:@"edit" style:uibarbuttonitemstylebordered target:self action:@selector(toggleedit)];     self.navigationitem.rightbarbuttonitem = editbutton;     [editbutton release];      [super viewdidload]; }  - (void)viewdidunload {     self.eventsarray = nil;     [super viewdidunload]; }  -(void)toggleedit {     [self.tableview setediting: !self.tableview.editing animated:yes];      if (self.tableview.editing)         [self.navigationitem.rightbarbuttonitem settitle:@"done"];     else         [self.navigationitem.rightbarbuttonitem settitle:@"edit"]; }  - (void)dealloc {     [managedobjectcontext release];     [eventsarray release];     [super dealloc]; }  - (void)didreceivememorywarning {     [super didreceivememorywarning]; }  #pragma mark - #pragma mark add event  -(void)addevent {         routine *routine = (routine *)[nsentitydescription insertnewobjectforentityforname:@"routine" inmanagedobjectcontext:managedobjectcontext];      routine.name=entered;      nserror *error = nil;     if (![managedobjectcontext save:&error]) {         // handle error.     }     nslog(@"%@", error);      [eventsarray insertobject:routine atindex:0];      nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:0];      [self.tableview insertrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];      [self.tableview scrolltorowatindexpath:[nsindexpath indexpathforrow:0 insection:0] atscrollposition:uitableviewscrollpositiontop animated:yes]; }  -(void)showprompt {     alertprompt *prompt = [alertprompt alloc];     prompt = [prompt initwithtitle:@"add workout day" message:@"\n \n please enter title workout day" delegate:self cancelbuttontitle:@"cancel" okbuttontitle:@"add"];     [prompt show];     [prompt release]; }  - (void)alertview:(uialertview *)alertview willdismisswithbuttonindex:(nsinteger)buttonindex {     if (buttonindex != [alertview cancelbuttonindex])     {         entered = [(alertprompt *)alertview enteredtext];         if(eventsarray && entered)         {             [eventsarray addobject:entered];             [tableview reloaddata];             [self addevent];         }     } }  #pragma mark - table view data source  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [eventsarray count]; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";      // dequeue or create new cell.      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      if (cell == nil)     {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease];     }      cell.textlabel.text = [eventsarray objectatindex:indexpath.row];      cell.accessorytype = uitableviewcellaccessorydisclosureindicator;      return cell;  }  // override support conditional editing of table view. - (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath {     // return no if not want specified item editable.     return yes; }  -(void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath  {       if (editingstyle == uitableviewcelleditingstyledelete) {           // delete managed object @ given index path.          nsmanagedobject *eventtodelete = [eventsarray objectatindex:indexpath.row];          [managedobjectcontext deleteobject:eventtodelete];           // update array , table view.          [eventsarray removeobjectatindex:indexpath.row];          [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:yes];           // commit change.          nserror *error = nil;          if (![managedobjectcontext save:&error]) {              // handle error.          }      }  }` 

cell.textlabel.text = [eventsarray objectatindex:indexpath.row]; 

this causing problem because ....... assigning routine class object text textlabel......

cell.textlabel.text = [(routine *)[eventsarray objectatindex:indexpath.row] <thepropertyyouwishtoassign routine class>]; 

or <**updated code***>

routine *temproutine = (routine *)[eventsarray objectatindex:indexpath.row];     cell.textlabel.text = temproutine.name; 

<**updated code***>

in case.

in alert view delegate .....

 if(eventsarray && entered)     { //******it insert object in coredata.... duplicating data?            routine *temproutine = (routine *)[nsentitydescription insertnewobjectforentityforname:@"routine" inmanagedobjectcontext:managedobjectcontext]; temproutine.name = entered;            [eventsarray addobject:temproutine];            [temproutine release];             [tableview reloaddata];              [self addevent];      } 

thanks,


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -