Choppy Scrolling Animation for UITableView in iOS8 Using Dynamic Cell Height - uitableview

I'm working on developing a newsfeed where most cells have different heights from each other. So I'm using Apple's new built-in system to calculate the height of the rows dynamically in iOS8.
The problem happens when I have to load a new page. When I do that, then scroll back towards the top, the content size of the table appears to be smaller than it should and the loading of the cells is really choppy. So when I start scrolling upwards, I'll be at the 5th cell and then all of the sudden the 4th cell will jump down. I attached the project if you guys want to see my code: https://github.com/KhanFu/TableView-Dynamic-Cell-Height-Pagination
If you keep an eye when you're scrolling the table view, you'll see it jumps upwards. To re-create the bug, first scroll all the way to the bottom, so it loads the next page (11, 12, and 13). Then start scrolling upwards. For the clearest version of this, keep your eye on the number 7. Watch how it almost instantaneously becomes 6.
Essentially, when the content offset of the table reaches the bottom of the table, I adds an object to the table's data, then I add a row with insertRowsAtIndexPaths.
I've been banging my head against this problem for awhile now. Let me know if you need more information. Thanks!

Related

UITableview small lag at third cell

This video demonstrates the issue I am having
UITableView screen lag
I am loading a xib file with a fair bit of stackView and UIViews into my tableview cell. Each cell takes up about 80% of the screen so you would see two cells at max.
I am experiencing a small lag when I am scrolling to the third cell. If I scroll back up again and scroll down like what I did, the lag does not appear to be there anymore and the tableView scrolls smoothly for the remaining cell. If I reload the table and repeat the above step, I will get that lag again when third cell is just about to appear.
It "feels" like the program takes longer to load the xib file in cellForRowAtIndexPath for the very first time. And once it is loaded, it could be loaded nice and fast for any other cell. (That is just a feel though)
All my views have static data. I am finding that this small lag decrease as I removed more view from the xib file.
Is this pattern normal?
Note. In the video when I pull to refresh, the table is reloaded. I have reloaded the table just before the video starts. You will see that at the beginning and whenever third cell is just about to appear (or half way through scrolling second cell) there is a small jump in the table. And after that, everything scrolls butter smooth.
Xib file
XibFile screen shot

developing an infinite title slider with corresponding pageViewController

ok, I wanted to create these custom controls I've seen in this app:
DownTown App
an infinite title slider above and an infinite page view controller below. you can scroll title infinitely and after scrolling finished, corresponding page controller scrolls to target viewController in that direction.
and you can can scroll the view controller below, and above titleSlider also scrolls with that.
so I create these components but the result is not exactly what I want, because there were some challenges I couldn't solve them. here you can download the component:
http://github.com/hashemp206/HAInfinitePageController
the first problem is as as I scroll titles, the target cell rest at center of view. but as I scroll faster and more you see the title is not resting at center and I have to manually move that cell to the center with animation.
to clarify how this title slider scrolls infinitely, I have created a UICollectionView with 3 section. when scrollView reaches an offset limit, I will jump back to the middle section.
the second problem is when I scroll the below pageController slowly, the above title slider moves well and correctly, but when I scroll faster this synchronization gets corrupted, and the title slider scroll can't synchronize itself with below page controller.
so I'm asking you expert guys, can you see my developed component and guess why it is not working well?
or if you want to challenge yourself can you develop this component exactly?

Poor initial load performance with heightForRowAtIndexPath and UITableView scrollToBottom

I have a UITableView that reads information from CoreData via the proper mechanisms (using a FetchedResultsController, etc). This information is either textual, or a URL to a local image to load into the tableview.
Data needs to be populated in the table in a bottom-up fashion (similar to a messaging app). I am targeting iOS 8+, but if I use estimatedHeightForRowAtIndexPath, I get terrible jerkiness on 3+ multi line labels and images. The estimate seems way too far off unless it's a one line UILabel. My hunch is that the cell height is being estimated in a top down manner, such that cell heights are growing from top of cell to bottom of cell. This means that scrolling top to bottom is fine, but bottom to top is not, since the cell is being resized "downward" dynamically as I scroll upward.
I am currently using heightForRowAtIndexPath to calculate cell heights. The problem with this is that it takes a very long time for the view to initially load because cell heights are all calculated at once. I am using cell height caching to store cell height so that once the view has loaded, scrolling is buttery smooth.
So my question is this: how do you use heightForRowAtIndexPath without taking the 3-5 second initial load hit?
And follow up bonus question, is there any way to reliably use estimatedHeightForRowAtIndexPath when you have cells that are vastly different in height? We're talking anywhere from 44px to 300px. From what I've read, I can't use the estimatedHeight calculation at all in this situation.
I've exhausted all of the stackoverflow posts concerning estimatedHeight/heightForRowAtIndexPath and I'm now starting to look at the same posts more than once. So I'm stuck.
why woncha stuff a few rows in the table to populate the visible area and after
the viewDidAppear start stuffing older messages on top of the table one or two
at the time with animation none, automatic or whatever.
this way with the postponement of the uitableview population
me thinks you'd get a passable performance.
or you could do it the skype way, postponing population of the table
with older messages until after table bounces off the top edge.

UITableView Section Headers not visible when table in visible rect

I have a UIScrollView with 3 UITableViews stacked horizontally. I switch between these tableviews using a tab-controller on top. However, when I switch to the 2nd or 3rd tab and switch back quickly to 1st the section headers don't show. They display when I scroll the tableView. These are custom headers (jfyi). I tried calling setNeedsDisplay when the tableView is visible, but that does not help because as per Apple Docs :
If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the view’s contentMode property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed.
Since, only the geometry of the view is changing here, it does not help. Also this happens on all versions iOS 5~6.1 and on simulator and device. Thankfully, this does not crash the app, but its a problem nevertheless. Could someone help? I am attaching pictures for reference. First shows the problem, second: after scrolling the "head(er)less" tableview
EDIT:
I am using simple scrollRectToVisible:animated: to switch between tableviews. This does the trick but I just observed that when I set ...animated:NO all is okay. The problem happens when ...animated:YES
It seems the issue of displaying and scrolling taking place simultaneously for the respective tableview. So what you can do here is:
Remove the scroll animation
or
Just scroll the tableview to top on the tab press event
or
simply reload the tableView which is made visible

UITableView Flicker Effect

There are about 100 cells displayed in UITableView. So , when I scroll down or up too fast I see a flicker effect over UITableView.
I have also re-used the cells and I am not using reloadData in my code, but still I see flicker effect.
The content that I am displaying in each cell is only text.
I have also gone through this thread but did not found useful UITableView section headers are blank and flickering.
I think with a number of cells I noticed my old iphone 3g struggle every now and then when i was flicking for a quick scroll to the bottom.

Resources