views:

337

answers:

0

I setup a UITableView which does the following when you tap a section header:

  • Expand the section (inserting rows animated)
  • Scroll to the first item in that section also animated

Like this:

 [self.tableView beginUpdates];
 //Expand
 [self.tableView insertRowsAtIndexPaths:ips withRowAnimation:UITableViewRowAnimationFade];
 [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
 [self.tableView endUpdates];

The scrollToRowAtIndexPath seems to be the culprit because if I pass animated:NO it doesn't seem to happen. (I would like to be able to animate the inserts and the scroll though)

But for some reason after the animation completes the section headers bellow the expanded section are removed. It only happens when the section headers should be visible after expansion (the inserted cells don't completely push them out of view). They are visible through the animation but when it finishes they are removed. See the stacktrace below which I got from overriding removeFromSuperview on my section headers.

Stacktrace:

#0  0x00035330 in -[NameOfMyTableSectionHeaderClass removeFromSuperview] 
#1  0x016cd3f6 in -[UITableView(_UITableViewPrivate) _updateAnimationDidStop:finished:context:]
#2  0x016a2c85 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#3  0x016a2af4 in -[UIViewAnimationState animationDidStop:finished:]
#4  0x0082d81b in run_animation_callbacks
#5  0x0082d5f5 in CA::timer_callback
#6  0x0097dac0 in CFRunLoopRunSpecific
#7  0x0097cc48 in CFRunLoopRunInMode
#8  0x0104d7ad in GSEventRunModal
#9  0x0104d872 in GSEventRun
#10 0x0168a003 in UIApplicationMain

To me it seems like this removal from the UITableView must be what causes it to disappear. I guess the source is closed for the UITableView otherwise I would be able to look into a bit more myself. Unless there's some way I don't know about.

Does anyone know how to fix this? Thanks!