UITableViewCell Reuse issues with horizontal tableview - ios

I have a slightly complicated system that I am having some reuse issues with, wanted to get some feedback. Basically it is a vertical tableview, and each cell contains another tableview that is rotated 90 degrees, so that each cell scrolls horizontally. Each horizontal cell is also set up to scroll infinitely with paginated responses from an API. I am having issues where cells are copying on top of each other when the vertical table is scrolled down. I have reuse identifiers set up correctly and in each of the horizontal tableviews I am running the following:
- (void)prepareForReuse
{
[_horizontalTableView reloadData];
}
If I turn off reusing cells the issue doesn't happen, but the vertical scrolling performance suffers. I am wondering if its possible that reusing cells in this type of a set up just isnt possible? Any experience with this is helpful. Thanks.

This is not a direct way to solve your issue, but I believe if you use a horizontal scroll view inside each vertical cell, you will have this done faster and with less weird behaviours. I also believe this is not a standard way, so weird stuff will happen.
All you do is set or extend the content size of the scroll off screen continuously to create an infinite scrolling behaviour. Create views within the scroll view pragmatically to simulate each cell. Hope this helps.

Related

Swift: Did Tumblr add a UICollectionView in a UIScrollView?

I've been trying to replicate this effect for a couple days which was inspired by Tumblr.
I've previously asked questions on here with different approaches of the same problem but to no avail. I'm just curious as to how the engineers at Tumblr created a horizontal collection view, with two vertical collection views, and is able to scroll down without affecting the view above (without resetting the position of the view when you scroll vertically in a different tab).
Header Views
I tried this, but the header view was isolated and I had to scroll to the right to see the collectionView cells. This did not work.
Changing the topLayoutConstraint constant of my UIView (not cv header) with respect to the contentOffSet of the vertical collectionView.
This almost got the effect I wanted, except that when I scrolled horizontally, there was a huge gap between my collection view and if I scrolled in that new tab, the UIView would appear again because, again, topLayoutConstraint gets scrolled up depending on the contentOffSet of my vertical collectionView contentOffset.
Changing the position of the UICollectionView frame, and scrolling the super view up simultaneously with NSNotificationCenter.
Alas, this method did the same as method #2, except that the vertical collection view cells scrolled faster than the super view.
I ran out of options to make this work so I will show you in detail what's attempted to be replicated (also note the scroll bar on the right):
Note when I scroll down the first tab. I switch, and then scroll down further. Originally, as I've said, there would be a gap between the second main CV, and when I scrolled, the view would reposition as if were scrolling up again. On here, the view on top keeps going up. So I'm curious as to what method Tumblr engineers used to do this. UICollectionView inside UIScrollView? Other suggestions?
I believe there is no UICollectionView involved. It looks like UIPageViewController and each its page is a UITableView.
Perhaps the UIPageViewController sits in a UITableView as well - the header also moves up when you scroll. This main table has only one cell (and a header) which is occupied by the UIPageViewController.
Hope it helps.

Two UIViews & one UICollectionView inside UIScrollView (or better approach)

I need to have iOS app with screen like this:
screen
The idea is when user start to scroll down the first UIView to move up until the second UIView reach the top where it will stick and only UICollectionView will continue to move up.
Currently I'm using this structure
UIScrollView (main scroll)
UIView (some banners)
UIView (UISegmentedControl)
UICollectionView (grid with items, scroll is disabled, main scroll is used)
I manage to do it, but I needed to set UICollectionView height constraint manually in the code (calculated based on all items in grid) in order to appear in UIScrollView (everything else is handled by AutoLayout in Storyboard). The problem with this is that UICollectionView think all cells are visible and load them, so the whole recycling & reusing thing does not work. It's even worst because I use willDisplayCell method on UICollectionView to load more data when last cell is displayed, but now it load all pages at once.
My question (actually they are 2)
How can I fix the issue above?
What is the right way to achieve this functionality? Maybe my whole approach is conceptually wrong?
Collection view is a scroll view itself. So maybe you could have same functionality only with Collection view with sections or even custom layout?

horizontal scrolling for each section in a table view

I want to implement a UICollectionView with multiple sections which each section scrolls horizontally and independently like the attached image
I suggest you to use UITableView with customized UITableViewCells with UIScrollView as subview on its contentViews.
There are many samples, for example here
You can use multiple UICollectionViews in table cells. The tableView will scrolls vertically and The collection views can be configured to scroll horizontally by setting particular set of properties which will restrict them to scroll vertically, and they will only scroll horizontally. One constraint to consider is it is much more difficult to do animations that need to move from one table cell to another and you can't use a neat single change of collection view layout to animate all the items in your table view. But if these constraints aren't a problem then this is a relatively easy solution. I also tried it once. It worked for me. Hope that it works for you as well.

UICollectionViewCells disappear when going out of UICollectionView frame

Consider the following:
I have a UICollectionView with a size of 400x400. This UICollectionView has 5 UICollectionViewCells which also have a size of 400x400.
Clip to bounds is set to false so that my UICollectionViewCells will be visible (this does not work, I can only see 1). I want this so I can use paging. When I start scrolling there are 2 cells, but when the scrolling snaps, the previous cell disappears and I can only see 1 cell.
I use dequeueReusableCellWithReuseIdentifier to retrieve cells to fill the collectionview. Can this be part of the problem?
How can I display the UICollectViewCells that are out of the collection view's frame?
You can't. What you describe for a problem is actually a feature of UICollectionView and UITableView. They reuse the cells that are not visible for performance and memory reasons. You might think of another approach like UICollectionView with custom layout if that would be possible for your requirement or directly use UIScrollView with paging and you rearrange all the views while is scrolling.

How can I make UITableView less sensitive to vertical scrolling?

I have table view that has more than 10 rows and inside each row I'm placing a hortizontally-scrolling scrollview (you can thumb through images much like in Coverflow).
The problem is that UITableView is too sensitive to vertical scrolling. When I'm trying to scroll left and right in a particular scrollview (inside of any cell), the table view starts scrolling up or down once it detects even the slightest movement of my finger upon the y-axis.
Is there a way I can change this and set a higher vertical-scroll threshold for the table view?
Here's a couple suggestions. Try them and see how they feel.
Suggestion 1
When you dequeue your tableViewCells, try calling this:
[tableView.panGestureRecognizer requireGestureRecognizerToFail:cell.scrollView.panGestureRecognizer];
Suggestion 2
Try setting this on your tableView:
self.tableView.delaysContentTouches = NO;
That property defaults to YES. It delays touches to the content of the table view cells by a fraction of a second, to help it recognize the difference between a tap and a drag.

Resources