Scrolling multiple UICollectionView using one IOS set

I am working on an application where I have a UITableView and in each uitableview cell I have a uicollectionview scrolling horizontally.

Now what I want is that: When I view a single view of a collection in any direction, then all other collections in my table should scroll accordingly in that direction.

I tried using scrollview delegates but it doesn't work correctly.

I am stuck with this issue. I looked on the internet but couldn't find anything.

Do you need help! Thanks to

+3


source to share


2 answers


Ok, I checked my code, what I am doing: I have a tableView on the left side of the screen, and otherwise a UIScrollView, inside which I had a top view whose width is collectionView.contentSize.width, and below that view, a collectionView with a height equal to screen height, and its width equal to its contentSize.width. After that, the ScrollView only scrolls horizontally and the CollectionView only scrolls vertically, so when the table is scrolled horizontally, the TableView remains and the Header and Collection view scrolls horizontally, and if you scroll vertically, the Header remains stationary and the Collection and TableView scrolls into one and the same time (you need to bind your delegates).

enter image description here

What am I doing in UIScrollViewDelegate



pragma sign - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == _scrollView) {
        if (scrollView.contentOffset.y > 0  ||  scrollView.contentOffset.y < 0 ) {
            scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
        }
    } else {
        _tableView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);
        _collectionView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);
    }
}

      

The height of the cells in the tableView and the height of the cells in the collectionView were the same.

+5


source


You can coordinate two table views by declaring the containing view controller as UITableViewDelegate and using the scrollView delegation method:

// say tv0 and tv1 are outlets to two table views
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tv0) {
        self.tv1.contentOffset = self.tv0.contentOffset;
    } else if (scrollView == self.tv1) {
        self.tv0.contentOffset = self.tv1.contentOffset;
    }
}

      



To get this first, first with two simple table views with the same length content. You will need to add conditional logic to handle if one view has more content than the other.

+1


source







All Articles