UITableView with a UIView underneath the Cells - ios

I have a UITableView and below the custom cell (in IB) I have inserted a UIView. The UIView gets set to hidden when viewDidLoad() gets called and is only displayed when there is no data in the UITableView. This works great and servers my purpose.
The problem is that even when the UIView is hidden, the scrolling on the UITableView considers the view to be present. i.e. The vertical scroll with scroll well below the last cell, covering the area where the UIView exists - even though its blank and nothing is displayed.
I have tried to hide the UIView but this doesn't help either. How do I get the scroll to not extend to the area covered by the UIView?
Edit:
The image on the left is how IB looks. I have added a UIView as a subview of the TableView. The image on the right is the large scroll space below the last cell.
Expected behavior: When the view is hidden, the scroll view only scrolls until the last cell.

If your view is displayed only when there is no cells, you could just add it over your UITableView (or behind it if your UITableView's background is clear) and hide it when you have cells to display. Just be sure to add your view as a sibling of your UITableView and not as a child view of your UITableView.

Related

UITableView Footer is not showing

enter image description here The Controller is UIViewController.
I have a UIScrollView in UIViewController. A Tableview is added as a subview upon the scrollview. The Scroll view content size is bigger than the screen size. There is a footer in the Tableview. When I am reloading the Tableview first time with the data then the Footer is not displaying but when I started the scroll then the footer is not displaying properly.
Could you please guide me, how to make this resolve.
Thanks
Firstly, it's wrong practise to add UItableview inside scrollview, because tableview already has scrollview underneath it and will adjust the content size of tableview automatically depending on the content you add.
Can you please let me know the reason why you have added tableview inside scrollview?
Remove tableview from scorllview and everything show work fine.

Need assistance showing custom UIView when UITableView is dried down

I am trying to achieve whatsapp style drag tableview to show custom view, here is the screenshot
but I am clueless how to show custom UIView on top of UITableView when UITableView is dragged down
You can place your UIView behind the table view, and have its height grow as you drag down. Where you read the scroll offset for your table views scroll delegate.

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.

Scrolling up UICollectionView don't move a UIView above it

I am working in a profile ViewController. This profile has a main image in a UIView subclass and a CollectionView gallery with some images. I would like to be able to scroll up the UICollectionView and move the UIView too, and if I scroll down, I want to watch again the UIView when the collectionView first item is showed again.
I have tried to do this adding the collectionView and the UIView to a ScrollView, but the UIView only scroll up if I touch it.
In this picture you can see my problem
Thank you in advance
You need to make the view at the top a Header View of the collection view.
Essentially it needs to be an actual part of the collection view if you want this action. (That's the easiest way anyway).
So the collection view will take up the whole screen but it will have a header view. Then when you scroll the collection view the header will move out of view and then come back in when you scroll down again.

UITableView: scrolling outside bounds hides cells

I have an UITableView that does not fill the whole screen, so there is some space at the top and the bottom of the screen. This table uses table.clipToBounds = NO and table.bounces = YES.
But when scrolling the cells outside the original frame of the table, the cells are hidden. I know that's the normal behavior of UITableView to increase performance. But is it possible to define an area at the top/bottom of UITableView within which the cells are not hidden? Or even set a cell property to be "always" visible?
Subviews outside bounds of superview are hidden (table view's cells are also its subviews). That's just how iOS view hierarchy works, not really about performance. And it doesn't make any sense when a subview/cell is displayed on the screen while user cannot interact with it (because it's out of bounds). In particular, table view reuses cells that go out of its bounds, so no, you cannot set a cell to be "always visible".

Resources