iphone - What is a good way to animate UIViews inside UITableViewCell after a callback? -


we couldn't find way animate uiviews inside uitablecell action callback.

suppose in scenario click on button on uitableviewcell , fires off asynchronous action download picture. suppose further when picture downloaded want uiview in cell animate picture give user visual feedback new presented.

we couldn't find way track down uiview invoke beginanimation on because original cell user clicked on might used row due nature of cells being reused when scroll , down in table. in other words can't keep pointer uitableviewcell. need find way target cell , animate if row visible , don't animate if row scrolled out of range.

keep cell object different object being animated cell holds uiview. when animation callback occurs check make sure uiview still exists and, if does, animate changes.

when cell object gets bumped off screen , recycled, release uiview have been animated , create new one. when animation callback occurs have nothing because uiview no longer exists.

a modification of above keep sort of object in uiview callback can check see if animation still appropriate. sort of unique identifier picture being downloaded. if identifier changes, no animation needed. if matches, animation.


edit:

- (uitableviewcell *)tableview:(uitableview *)tableview          cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *myidentifier = @"mytablecell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:myidentifier];     if (cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle                                        reuseidentifier:myidentifier] autorelease];     } else {         uiview *oldviewtoanimate = [cell.contentview viewwithtag:1];         [oldviewtoanimate removefromsuperview];     }      uiview *viewtoanimate = [[uiview alloc] initwithframe:cgrectzero]; //replace appropriate frame     viewtoanimate.tag = 1;     [cell.contentview addsubview:viewtoanimate];      return cell; } 

when spawn download process pass in [cell.contentview viewwithtag:1]. when download done, update appropriate view. if table cell reused view no longer have superview , not update wrong cell.

there things can make more efficient basic idea. if have custom uitableviewcell bit different.


edit 2:

to reuse viewtoanimate objects make sure updated if parent cells recycled, following:

- (uitableviewcell *)tableview:(uitableview *)tableview          cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *myidentifier = @"mytablecell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:myidentifier];     if (cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle                                        reuseidentifier:myidentifier] autorelease];     } else {         uiview *oldviewtoanimate = [cell.contentview viewwithtag:1];         [oldviewtoanimate removefromsuperview];     }      uiview *viewtoanimate = [self viewtoanimateforindexpath:indexpath];     viewtoanimate.tag = 1;     [cell.contentview addsubview:viewtoanimate];      return cell; } 

viewtoanimateforindexpath need to:

  • check see if viewtoanimate has been created indexpath
  • create viewtoanimate if there isn't one
  • save reference view can looked indexpath
  • return viewtoanimate table cell can use it

i don't know enough data structure you. once download process completes can call same method view , animate it.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -