Grouped UITableView Footer Sometimes Hidden On Quick Scroll
OK, this one is a puzzler. There is one similar post but it's not similar enough to count, so I'm posting this one. :)
I've got a grouped UITableView with a header and footer. The footer includes two UIButton views, side-by-side. Nothing major.
Now … there is a toggl开发者_运维知识库e button in a UIToolbar at the bottom for more/less info in this table view. So I build my index paths to delete/insert with fade row animation, all the usual ingredients, sandwiched between beginUpdates
and endUpdates
calls on the UITableView … and this works fine! In also happens that my footer can sometimes be pushed off past the bottom of the display.
Here's where it gets weird. If I drag my finger up the display, scrolling the view upward, I should see that footer eventually, right?
Well … most of the time I do. BUT, if I flick my finger up, for a faster scroll, the footer is missing. Even if you try to tap in that area - no response.
However, if I scroll back down again, just to hide that footer (or rather hide the area where the footer would normally be), and then scroll back up, it's there once again!
This only happens when inserting rows. If I delete rows, the footer stays put … unless of course it was already hidden and I didn't perform the aforementioned incantation to get it back. :)
I am trying to trace through this, but to no avail. I suppose tracing through scroll operations is a bit of a crazy proposition! Perhaps some creative logging … suggestions, anyone? Or is this a known issue in 3.1 where row insert/deletes are concerned? (I don't recall seeing it until 3.1.)
OK moving ahead with our app, I stumbled more often over the redraw problem. After investigating hours and hours it seems that there is only one solution [tableView reloadData]. But there is a better solution (than in my first answer) for the broken animation. You can get a method call as soon as the animation is finished with this and there is no longer a "flash":
[UIView beginAnimations:nil context:[NSNumber numberWithInt:section]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
...do something on the table..
and commitAnimation
In your animationDidStop do the table reload.
But it's still tricky to find the correct moment/event for the reload, in particular if you are working with the fetchedResultsController which is firing his delegate methods on his own as soon as a attribute is changed which is used for sorting.
All this is still an exercise of programming around a problem with cell view updating which shouldn't be one.
Have you tried to change something in the footer in the method you call from your footer buttons e.g. changig text on a UILabel in the footer? That's what I try to do. BUT: The footer is not updated. Or to be more precise: It is updated, but not on the screen. Scrolling the footer out of the visible array and back shows the correct footer. So there is an update problem.
So perhaps you see the same redraw-Problem?
I tried to call all the methods (needslayout needsDisplay etc etc) nothing worked. The only way to solve this is a table or section reload, but this kills my rowAnimation. Next I tried to call the reload via a notification hoping the animation is finished before the notification is called. Nope. At the end I use a scheduled timer to reloadData with 100-200ms delay started at the aned of my insert/delete rows. So the animation is finished before the load.
It looks like it is working now, but the price is a short "flash" with a wrong footer before it gets updated.
UPDATE
Ok, with the support of Skie I solved my redraw problem. Please refer this.
I'm not sure if this approach or at least the idea can solve yours too, but perhaps....
精彩评论