ios - Best way to select a row after inserting it? -


i'm working on ios app using navigation based, coredata template. select , "scroll visible" row after inserted table view. ideally i'd select it, deselect , select again, in order kind of flashing effect.

as using method, template provaides, namely:

#pragma mark - fetched results controller delegate  - (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller {     [self.tableview beginupdates]; }  - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id <nsfetchedresultssectioninfo>)sectioninfo            atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type {     switch(type)     {         case nsfetchedresultschangeinsert:             [self.tableview insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade];             break;          case nsfetchedresultschangedelete:             [self.tableview deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade];             break;     } }  - (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject        atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type       newindexpath:(nsindexpath *)newindexpath {     uitableview *tableview = self.tableview;       switch(type)     {          case nsfetchedresultschangeinsert:             [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationtop];                 [self.tableview selectrowatindexpath:newindexpath animated:yes scrollposition:uitableviewscrollpositionmiddle];              break;          case nsfetchedresultschangedelete:             [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];             break;          case nsfetchedresultschangeupdate:             [self configurecell:[tableview cellforrowatindexpath:indexpath] atindexpath:indexpath];             break;          case nsfetchedresultschangemove:             [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];             [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]withrowanimation:uitableviewrowanimationfade];             break;     } }  - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller {       [self.tableview endupdates];  }   

i bit confused , don't know, put selection code.
if put a
[tableview selectrowatindexpath:<#(nsindexpath *)#> animated:<#(bool)#> scrollposition:<#(uitableviewscrollposition)#>]
into
- (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller,
selects row, deselects , scrolling doesn't behave should either.

in method controller:didchangeobject:atindexpath:forchangetype:newindexpath: change section:

case nsfetchedresultschangeinsert:    [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade];    [tableview scrolltorowatindexpath:newindexpath atscrollposition:uitableviewscrollpositionmiddle animated:yes];    insertedindexpath = newindexpath; //remember selection break; 

and add method uiscrollviewdelegate:

- (void)scrollviewdidendscrollinganimation:(uiscrollview *)scrollview {    [self.tableview selectrowatindexpath:insertedindexpath animated:yes scrollposition:uitableviewscrollpositionnone]; } 

remember add insertedindexpath variable.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -