AutoLayout. Stick UITableView to the bottom of UIScrollView - ios

I need to achieve layout shown below. There are UIView and UITableView inside UIScrollView:
UITableView should be aligned right at the bottom of UIScrollView
UITableView should not have scrolling, so it's height should be adjusted according to content.
Row count is not static value.
Here are the constraints of UITableVIew:
If I understand AutoLayout correctly, everything should be fine, but as result I get UITableView's height to be 0. What's wrong with this setup?

I don't know what you are displaying above the UITableView but the normal setup for displaying something, that is above the tableView and scrolls with the tableview would be to use a UITableView (It is a Subview of UIScrollview and thus handles the scrolling itself) and add the things that you want to display above it as a tableHeaderView to your tableView.

Related

dynamic, custom layout UICollectionView embedded in UITableViewCell

I have UITableViewController with 1 section and header with UISegmentedControl inside.
If user presses first segment we should display UITableView cells
If user presses second segment we should display custom vertical scrolling collection grid with collection items below that header
possible solutions:
change UITableViewController to UICollectionViewController, and UITableViewCells to UICollectionViewCells. This should work but I'm trying to avoid this solution
UICollectionView embedded in UITableViewCell. Setting UICollectionView scrolling enabled to false, adjusting UITableViewCell's height to fit entire UICollectionView's contentSize.height. In systemLayoutSizeFitting(...) method of container (UITableViewCell) we call layoutIfNeeded on container and on contained UICollectionView and return UICollectionView's contentSize.
problem:
(re)calculation of entire UICollectionView contentSize requires a lot of work if we have hundreds of items (cellForItemAtIndexPath for every item). Want to avoid this somehow. Maybe we can increase container (UITableViewCell) height during scrolling UICollectionView which is embedded inside.
Same as 2 but we have fixed size container UITableViewCell (same height as view without header) with UICollectionView inside. When we scroll UITableView to the very bottom UICollectionView scroll should continue scrolling.
problem:
I don't understand how to deal with 2 instances of UIScrollView with scrollingEnabled = true for both. I think this could be solved with pan gesture recognizer delegates. If it is so I need help here.
I would personally opt for number 1 and completely avoid number 2. For number 3, you could set tableView.scrollingEnabled = false when the second segment is tapped. Set it to true when the first segment is tapped. That way, when it's false, the UICollectionView in your UITableViewCell can still scroll.
This tutorial may help with putting a UICollectionView in a UITableViewCell.

How to make a Horizontal and vertical scrolling TableView in iOS using storyboard?

here is my design structure
I was wondering about creating a horizontal and vertical scrolling tableview. I have tried a tableview inside a scrollview but I failed miserably. What to do?
I use swift4 but I wanted to do in storyboard.
The nature of content is like an excel sheet with lots of horizontal and vertical scrolling rows and columns of data.
Actually you can do this using a hack. Put the tableView inside a scrollView. Then you should give a dynamic width to the tableView by specifying a width in storyboard for tableView or any child view of that scrollView(So we get the horizontal scrolling).You have to adjust some constraints depending on your requirement
Mine worked fine but as many users have said try a collection View if its easy
Note. There is a default scrollView within a tableView, So adjust your height of tableView in a way so the scrollView of tableView work and not the parent scrollView, while scrolling from top to bottom
Instead of using TableView try using collection view, there you can use horizontal and vertical scrolling using storyboard?
Try to use collectionview instead of tableview.
If your requirement demands use of tableview anyhow, then you can use tableview within scrollview.
In tableview within scrollview approach, you need to distinguish your parent scrollview as well as tableview's scrollview. Try to differentiate parent scrollview and tableview's scrollview with different tags. Because both scrollview will call delegate methods of viewcontroller, if implemented. Just check tag of scrollview in all delegate methods of scrollview and perform action accordingly.
As per my understaing you want a view which you want vertical scroll view and horizontal inside it.
So here my suggestion is to use UITABLEVIEW for vertical scrolling and UICOLLECTIONVIEW for horizontal scrolling inside tableview
Both will work fine

UITableView inside UIScrollView - Cell not clickable

I have a problem with a UITableView not detecting touches.
In an iPhone-only app, I have a UIViewController, which containts:
UIScrollView
UIView (let's say a content view)
Some labels
UITableView (last)
The labels have a dynamic height, because they contain some text that I must retrive from the web, so I'm using auto layout.
I'm setting the content size of the UIScrollView inside the viewDidLayoutSubviews method, and I'm doing this by summing UITableView.frame.origin.y and its height.
Here comes the problem: when the labels contain only some words and the UITableView does not exceed the iPhone screen size, everything works ok. But when they grow, and the UITableView gets pushed down, when I scroll down I can't click on the cell anymore. Also, if when loading the view the table is half visible and half not, I can click the visible cells, but if I scroll down, I can't click the others.
I'm using swift 2 and Xcode 7.
Here is an example:
Clickable:
Unclickable:
Do the following thing:
yourView.clipToBounds = true
Now, if UITableView does not appears means your UIView is not same bigger to hold down UITableView.
Make sure that your UIView height is bigger to hold the contents in it and then try to tap on it.
Updated:
If you are using AutoLayout, then do the following thing.
Give the fix height to UIView
Take the outlet of height constraint of UIView
Now, in viewDidLayoutSubviews change the constraint of UIView to UITableView contentSize height.
self.heightConstraint = self.tableView.contentSize.height
Let me know, if this helps!
Adding some info to the #Rémy Virin's answer here:
From Apple Documentation, you shouldn't embed a UITableViewinside a UIScrollView.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Addition:Solution Since you want to scroll the content above table also, the one solution is place a Header View for the Table and place the Content over there to make it Scroll along the Table View.
If you use Autolayout, no need to specify contentSize to UIScrollView as it will automatically expand by taking the height of its subview.
In your case, increase the height of the Base UIView (content view as mentioned by you) which holds the tableView when the tableView height increases.
UITableView becomes unresponsive when it extends below its container view.

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!

UIScrollView in UITableView Header not scrolling

Following problem: I have a UITableView with several cells. The table has also a header, in which i added a UIScrollView, which should scroll horizontal.
So now when i scroll around the screen the table will always be scrolled, but not the UIScrollView in the header, even if i scroll horizontal in the area of the header.
So it seems the table is managing all the scrolling. How can i setup the UITableView scrolling so that the UIScrollView in the header handles the horizontal scrolling for the header area.
I tried to set delegate of the UIScrollView and tried the function from the UIScrollViewDelegate, - (void)scrollViewDidScroll:(UIScrollView *)scrollView, but only the table calls this function.
I hope you can help me.
Set content Size properly. Content size should be the width and height till where you want to scroll.
scrollView.contentSize=CGSizeMake(100,960);

Resources