UITableView with Pages that contain X rows - ios

I'm trying to achieve a UITableView that can be scrolled horizontally by page, each page containing 10 rows (every row has the same height)
I know UITableView extends UIScrollView but pagingEnaled + contentSize doesn't seem to do the trick so I'm stuck
Basically I have a UITableView with 100 rows and I'd like to have pages of 10 that I can scroll horizontally, How can I achieve this?

There are 2 solutions:
Either you go with the newly added in iOS6 UICollectionView (but then you need to set as a minimum target for your app iOS6)
or you add 3 UITableViews inside a UIScrollView next to each other and move the first or last UITableView when a new page is displayed to the UIScrollView.
There is a ready to use implementation for this here: https://github.com/arconsis/ARTableViewPager

Related

Scroll horizontally in UITableView - Swift 3, iOS

I need to horizontally scroll through a list of thumbnails at the bottom of the screen that shows all the user's recently taken photos / videos.
I created a UIScrollView with a UITableview inside of it.
Is this the correct approach because I can't seem to find an override method in its superclass for scrolling direction?
Most of the topics I can find online deals with putting a UIscrollview inside a TableCell, which will not work for my specific application?
The hierarchy is:
View > Scroll View > Table View > Table Cel > Content > PhotoThumbnail
Below is a screenshot of what I'm trying to do:
I am not really sure why do you want to use UITableView for horizontal scrolling which lay out there cells in vertical manner. If you want horizontal scrolling I would recommend using UICollectionView where cells can be added horizontally or vertically or both.
Still if you want tableview to be scrollable in horizontal direction I would suggest you to check this project to get inspiration or using it.
https://github.com/alekseyn/EasyTableView
Instead of using UITableView you can use UICollectionView to achieve the desired result i.e, horizontally scrollable cells with imageView and other elements that you need.

Scrolling Views Along with Collection View Cells

On my view controller I have 1 collectionview underneath 2 views at the top of the view controller I set the collection views height based on the size of the views so the collectionview is big enough that it doesn't need to scroll. All 3 views are inside of a scrollview so that I can scroll the views and the collection cells seamlessly. This feels very inefficient but i can't think of another way of providing this sort of seamless scroll between the views and the collectionview. Is there something else I can do to achieve the same or at least similar result?
EDIT: https://gyazo.com/8e5febea0974b0e6e0660f1714d67cbc this will hopefully explain it better. label is the view inside of the scrollview above the collectionview and four buttons are collectionview cells. Now if I add 20 buttons instead of only 4 I can scroll the collection view but it won't scroll with the label. This might also help explain what I'm trying to achieve - http://jsfiddle.net/hDwPH/
Ignore This Dummy Code
From the screen shot, I assume that your view controller consists of
1 UILabel
Multiple UIButtons
Only 1 item per row
If so, you should consider using UITableView instead. The UILabel will be section header, The UIButtons will be the rows (UITableViewCell). So your UITableView consists of 1 section, 20 rows.
If you want your UILabel to float along with the UIButtons, set the
UITableView style to UITableViewStyleGrouped
If you want your UILabel to remain fixed, set the UITableView style to UITableViewStylePlain

Mixing UIScrollViews and UITableViews

If you look at the Featured tab of the Apple App Store app on an iPhone 6, there is a unique UI layout that I can't figure out how to replicate.
At the very top there is a navigationBar. Below this there is a UIScrollView that animates through a number of featured items. Below this is what appears to be a UITableView with a number of custom programmed cells.
My first guess was that the UIScrollView at the top was added to a custom cell at the top of a UITableView. If you swipe up the UIScrollView moves with the objects below like it is a cell. You can see that the vertical scroll indicator starts at the top of the UIScrollView.
The part that is unique is that if you swipe down, the objects below the UIScrollView move down like a UITableView and the UIScrollView stays in place. This means that the UIScrollView is not a custom cell at the top of a UITableView.
I tried making this work a number of different ways but I can replicate this. Does anyone know how this can be done?
You can use a tableview header,the header is a scrollview
If you scroll tableview up,just use tableview default behavior,the header will scroll up.
If you scroll down,use UIScrollViewDelegate to calculate the tableview header new frame,and adjust it.So it remain at top
Not sure if I got you correctly, you may use UICollectionView as vertical scroll. Then, you create a custom UICollectionViewCell, each with horizontal scroll.
I haven't tried it though but done something similar to this. Hope you find a way!

Scrolling in iOS for a component with variable height

I am trying to make a vertically scrolling view, where the screen has three sections and scrolls up or down in totality (i.e. all the three sections move up and together together)
There are three parts of the screen - Section 1, 2 are fixed height and section 3 is scrollable depending on the number of row data that the server sends to the client
How do I achieve this in iOS - is there a way of having
Parent View
Section 1
Section 2
Section 3
and then call scrolling function on the Parent View? I don't want to go into the messy details of manually adjusting the height of the Parent View by checking the Section 3 height (variable) and adjusting accordingly - surely there is a way in iOS programming to encapsulate all this behaviour in a clean little class. Thanks for the advice
This behavior can be realized with native iOS components.
There can be different implementations but I would choose this one:
UITableView
HeaderView
UIView (Section 1)
UIView (Section 2)
Content View (Section 3)
UITableViewCell (Section 3 cell representing your first row data)
...
In Xcode Interface Builder, you can add an header view by dragging a view on top of the displayed prototype cell.
With this architecture, the HeaderView will have a fixed height, and the ContentView will have a dynamic height. And when you scroll, the whole UITableView will scroll.

Paging event in UIScrollView with multiple UITableViews iOS XCode

I've created one UIScrollView with multiple (10) UITableViews to show content. The UIScrollView allows the user to horizontally scroll to show the different UITableViews. This is a specific use case in this app which we want to implement this way.
The UITableViews all represent one week in the total of ten weeks. What I want to do is after the scrollview scrolled to another UITableView (week) the Navigation bar title changes to "Week x". The UIScrollView has paging enabled and works like a charm.
The question however is how do I keep track of the pages changing? I cannot seem to implement a SwipeRecognizer, Touches began or the ScrollViewDidScroll. Is there a way around this?
I think I have the same question as this guy, but no satisfying answer so far:
How to find which table is scrolled with multiple UITableViews on UIScrollView
You should implement the UIScrollView delegate method scrollViewDidScroll: and check the content offset.
For example, When the content offset x value is 0, then you're viewing the first table view. When it's 320 you're watching the second table view and so on.
320 is just an example value. You should change this to be the width of the UIScrollView.

Resources