UITableView not reloading data when not visible? - ios

I'm puzzled with this.
I have a UIScrollView and inside I have placed 4 tableViews.
The whole thing is used to allow scrolling horizontally and switching tableViews like the Groupon app.
As soon as you start scrolling the 4th (left or right) tableView, is moved in the scrollView and a reloadData is initiated on that tableView, so it will load the data from the datasource for that category.
However, when I scroll into that tableView, it still has the data from the previous category, meaning the cell's didn't get refreshed.
Can anyone shed a light on why this is happening?
I'm guessing only that because the tableView is not in a visible frame when I call the reloadData command, actual drawing is not happening in the tableView (the datasource methods are being called normally, but no drawing is happening).
Any ideas, or tips ?

Related

ScrollViewDidEndDecelerating gets called every time when I select cell

I know that it would be repeated question but I really stuck on it. My first CollectionView’s each cell has another collectionView as a subview. My first CollectionView has three cells with same width and height and my Second collectionView has 27 cells. I want to show edge of next and previous cells at second cells of the first collection view and got it using the ScrollViewDidEndDecelerating delegate method of the uiscrollview but the problem is the he gets called even simple touch on any collectionview item. Please help me, how do I get rid of this shit?
If anyone wouldn’t get my point I can share code as well.

Weird issues when reloading data (iOS)

I have a collectionView, called parentCollectionView, which scrolls horizontally. Inside each reusable cell is a collectionView, called childCollectionView which scrolls vertical.
I am having a strange issue. When I reloadData() on the parentCollectionView, the cell will glitch/flicker for a fraction of a second, and if you are scrolled down, it will load the childCollectionView from the top. The weirdest thing, is that it only happens the first time you call reloadData() on the parentCollectionView. Everytime after that, there is no flickering, and doesnt force you to the top. And when I ditch the reloadData() method and use reloadSections/IndexPaths it will for load from the top everytime.
What the heck is going on?
I didn't call reloadData on the parentCollectionView. Instead, I called reloadData on the childCollectionViews that are visible and set the delegate/datasource to nil, to cells that have been deallocated (in prepareForReuse).
It seems as reloading the parentCollectionView via reloadData() is redrawing everything.

why tableview cells are starts flickering when they are going to be reused?

I'm building a chat interface. I'm using multiple types of tableView cells in UITableView. Table view cells are start flickering when new cell is added into tableView from reusablecell. I'm dequeuing tableview cells with following piece of code. How get scrolling smooth with out any flickering.
tableView.dequeueReusableCellWithIdentifier("MessageLessonTableViewCell") as! MessageLessonTableViewCell
The main reason for flickering is that, tableView is getting data to be attached late in time. So when you scroll, it takes time to switch from one type of tableViewCell to another. Plus you might be doing DB operations in cellForRowAtIndexPath which delays in returning tbaleViewCell. For implementing Smooth scrolling refer this

Adding a Scrolling Subview to a UITableView (NOT a Cell)

I'm creating my views programmatically. I have a UITableView in my UIViewController subclass that I want to add a scrolling subview to that is not a cell. I want to add some text-based subview to the UITableView that scrolls with the table and starts out above y=0 so the user will only see it if he pushes the table down. That is, it should reside above the first section of my table. If it helps for visualization, I intend to make something similar to those "scroll down to refresh" features and want some indication to the user that scrolling down causes a refresh. Is there any way to do this without something messy like using another UITableViewCell to represent it or abusing the UITableView delegate methods to move a view around whenever the user scrolls?
Simply using [tableView addSubview:] in my viewWillLoad only makes it appear for a split-second then disappear once the table data is loaded. This seems weird to me because UITableView is a subclass of UIScrollView, which is meant to hold other views in it. Using [tableView.backgroundView addSubview] does nothing.
P.S. Why not use a UIRefreshControl for this? I'm still undecided but leaning towards not using one because I don't like how slow that spinning wheel "feels" when the refreshes are usually very very quick. I've been looking at other options like flashing the background subtly and only showing a wheel if it's taking a longer time than usual.
I You can implement pull to refresh with only a table view
To do this using the scroll view delegate, since tableview is a subclass of scroll view.
Set view controller to be the tableview delegate and implement
(void)scrollViewDidScroll:(UIScrollView *)scrollView
When scrollview content offset y value passed a point, add a label to the viewcontroller.view not tableview. When you scroll back or release, remove the view.
You might also be able to add label to the table view and set the frame origin to negative y value, so when you pull the label will move into view (Never tested this do might not work)

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

Resources