ios - Get indexPath of Core Data object in UITableView -


i have uitableview i'm populating core data following nsfetchedresultscontroller:

- (nsfetchedresultscontroller *)fetchedresultscontroller {     if (_fetchedresultscontroller != nil) {         return _fetchedresultscontroller;     }      nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init];     nsentitydescription *entity = [nsentitydescription entityforname:@"event" inmanagedobjectcontext:_managedobjectcontext];     [fetchrequest setentity:entity];      nssortdescriptor *sort = [[nssortdescriptor alloc] initwithkey:@"date" ascending:yes];     [fetchrequest setsortdescriptors:[nsarray arraywithobject:sort]];      [fetchrequest setfetchbatchsize:20];      nsfetchedresultscontroller *thefetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:_managedobjectcontext sectionnamekeypath:nil cachename:@"root"];     self.fetchedresultscontroller = thefetchedresultscontroller;     _fetchedresultscontroller.delegate = self;      return _fetchedresultscontroller; } 

i have method attached "add" button adds new core data item database. object added, table updates , new object shown in correct spot according "date" sort in fetched results controller. new object added using today's date "date" attribute. add object this:

nsmanagedobject *newevent = [nsentitydescription insertnewobjectforentityforname:@"event" inmanagedobjectcontext:context]; [newevent setvalue:@"new client" forkey:@"name"]; [newevent setvalue:[nsdate date] forkey:@"date"]; nserror *error;     if (![context save:&error]) {         nslog(@"core data error!  not save: %@", [error localizeddescription]);     } 

now, part of "add" method, need select row new item added , segue edit screen. obviously, depending on other dates of items in table, anywhere.

i want select this, don't have indexpath:

[self.eventlisttable selectrowatindexpath:indexpath animated:yes  scrollposition:uitableviewscrollpositionbottom]; 

how determine row (indexpath) new object added @ can select properly?

thanks!

nsfetchedresultscontroller have method called: indexpathforobject:

if have inserted items during change processing (the frc delegate methods), select recent inserted item. can determine index path of object using method above.

or, keep inserted object last insert, , in didchangecontent delegate method, select inserted item , nullify variable kept (so further calles won't trigger segue).


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -