Using paging in UITableViewController - ios

I have a UITableViewController that looks like this:
https://www.dropbox.com/s/dy6o55qa8squi9f/Screen%20Shot%202015-04-14%20at%2000.13.29.png?dl=0
And i want to implement a paging system by using UIScrollView. Now from what i understood UITableView inherits from UIScrollView. Still i have no clue how to proceed to make this happen.
So what i want to be able to do is when the users enters the view i showed on the picture the user can swipe to get to another UITableView with different data of course.
I tried myself using gestures for a while but i learned that i should not use it and use this method instead. I have been trying out this for a while to but i am getting nowhere.
Some guidance or code snippets would be of great help!
I am using storyboards.
Thank you

If you want to page vertically up and down within the table view, set pagingEnabled to YES on it and set its contentSize. That might get to be an issue if you start having rows that don't line up with the contentSize perfectly though.
If you want to page horizontally between different table views, you need to put each table view into a UIScrollView, set it's contentSize to be the width of each of the table views summed together, and set pagingEnabled to yes on it.

Related

How to setup a UIScrollView to arrange content dynamically?

I am trying to create a user profile screen. The screen will have lots of information about a user. It will look similar to this AirB
From the looks of it, it seems to be some sort of scrollView? or is it a tableView or a collectionView? (because it seems that there are some rows in there i think)
Does any one here know how this type of view can be accomplished or can be setup?
EDIT two answers below says to use a UITableview, and 2 other answers says to avoid it. Are there any benefits/disadvantages to using either?
Use only one child UIView as i will call it ContainerView inside UIScrollView and then place your child views inside that ContainerView. Use constraint to trailing and leading and top and bottom of that ContainerView to UIScrollView. and use constraint for placing child views to viewController.view not to ContainerView to then iOS will find where child views have to be.
Good Tutorial to find out how to use constraint on scrollView
Apple Technical Note
Do Not use tableview in this case, this content is difficult to maintain in a table view, really, use a scrollview, as for how, a simple googling for "swift uiscrollview tutorial"
Tableview is the best solution for this kind of scrolling views but in the screen you have mapview if it updates every moment i.e. updates with current location then it is not recommended to use tableview.
In that case you can use scrollview with custom views add subview changing with parameters.
In one of my app i did same thing using Tableview. And for that tableview i created a custom cell which have such a big height and i added all the images,map,details of user in that. And it work similar to what you want.
If you want help reply to my answer

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?

How to make cell doesn't scroll along with other cell?

I am making an app that use table View Controller and static cell.
I want to make first cell don't scrolling while other can. This is a picture of what i am talking about.(Sorry for my bad English)
For example as in this picture, I want to make 9gag tab stay when scroll. If you play instragram you will see that when you scrolling the name of user will stay until you scroll into another one. However I want it to stay not changing when it encounter second cell.
Any suggestion?
Using UITableViewController would not help here. You can use these steps to get what you want:
1. Create a UIViewController.
2. Add UITableView as its subview.
3. Add another UIView as UIViewController's view's subview.
4. Using auto layout constraints, you can put UIView above UITableView
This way, you will get a sticky view at the top.
Ok, not exactly sure what you're after but i'll take a stab.
Firstly, if you want the section to remain in place until a new section of items is present, you just need have a look at sections. This is an automatic feature. You may not see it occur until you have plenty of items in the sections.
UITableView With Multiple Sections
There's plenty of stuff about it & not too hard to implement.
My other guess of what you want:
If you want it to remain static regardless of anything, perhaps you could just create a view and place it above the table view. why does it need to be a part of it if it doesn't change?

Adding subview to UICollectionView - disables scrolling

I want to add a subview to a UICollectionView in order to make a left panel that scrolls with the collectionview.
Using
[self.collectionView addSubview:myView]
all touches become disabled and I can no longer scroll the view. I've read that adding a subview to a collectionView like this is bad practice.. is this true? Why does it disable touches from reaching the collectionView event when
userInteractionEnabled = NO
I'm trying to do this: imgur link by grabbing the frame position of the first cell in each section, and adding a dot with to myView with the same y value.
Thanks for any help!
Adding subviews using the addSubview: method to a UICollectionView is very bad practice. It can cause a lot of different problems in the normal behaviour of the CollectionView. It can obstruct the views underneath it, capture the touch events, preventing them from reaching the actual scrollView inside the CollectionView, etc. The subviews added using this method will also not scroll as the other elements in the CollectionView do.
The correct way to do what you want is to implement a new type of UICollectionViewCell for the dots, and compute their locations in the prepareForLayout and layoutAttributesForElementsInRect: methods. Basically you'll have either one or two cells in each row. Which ones will have two rows will be determined by you in the methods I've mentioned.
In fact, Apple's docs have a perfect example that's even more complex than what you're trying you achieve. You should check it out from this link.
May I know the purpose of that scroll view ? Because, if you're looking for a subview that displays only a label or image etc., You can use custom collectionview cell instead if I am not wrong... Hope it helps :) :)

UIScrollView behavior is different in iOS8

I have the following layout
So it's basically a scroll view that occupies whole screen. Content size is set to triple-width and same height. Inside the scroll view - there is container view and three table views - one per page. Only middle table view is visible initially.
This allows me to use scroll view horizontal scrolling to navigate between the tables and vertical scrolling inside the middle table.
I know that Apple doesn't really recommend putting UITableView inside UIScrollView, but in this particular case I don't know how to implement it differently, and until iOS8 everything was working fine.
UIScrollView would not recognize any vertical scrolling (since content height was equal to scroll view height) and these gestures were passed directly to UITableView.
But starting in iOS8 - this getting broken. UIScrollView would allow some vertical scrolling and basically intercept scrolling gestures sent to UITableView.
I created a simple project that works fine in iOS7 but is broken in iOS8. Anybody has any idea how to fix this problem?
Link to the project: https://dl.dropboxusercontent.com/u/6402890/TablePaging.zip
I haven't been able to solve this and as I mentioned in comments had to re-write logic using built-in UIPageViewController class.
If I change the Class of your ScrollView in Interface Builder to UIScrollView, it fixes part of the problem. Now just the UITableView goes up and down, and I go left-and-right, but haven't gotten rid of the space at the top.

Resources