UITableView: scrolling outside bounds hides cells - ios

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".

Related

Stop UICollectionView hiding cells out of view bounds

I have a horizontal-scrolling UICollectionView which is nested in a UIView that is centred and occupies 80% of the screen width.
I want the UICollectionView to be visible screen edge-to-edge rather than constrained to the super UIView bounds.
I have set the following which shows the UICollectionView across the screen width:
collectionView.clipToBounds = NO
...but when dragging the collectionView, it hides cells when they are completely outside of the super UIView bounds even though they are partially visible on the screen, which leads to a weird flickering of blank space/cell.
Ideally, I'd like a way to prevent the hiding of the cells completely out of bounds. Is there a way to do this?
The UICollectionView has a maximum size of 3 cells, so I'm not particularly worried about any performance implications of having all cells visible all the time.
The only way I found is to enlarge the frame of the collection view (and its superview in your case) and add contentInset's to it. You might also want to update scrollIndicatorInsets.

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.

Invisible and not selectable objects in cells scrolling down a long static table view in IB

Actually I'm using XCode 7 and I'm trying to lay out a static table view in IB. I have "sizes classes" ticked (adaptive layout) and the table view is taller than the default square scene of 600x600 points. I can work fine with the cells in the top 600 points of the scene, that is its height.
When I scroll down the height of the scene, I can't select table cells by clicking on them in the scene (but I can in the outline). When I drag any object (e.g. a label) onto one of these cells, it goes into the view outside the cell and when I put the object inside the cell by dragging it onto that cell in the outline, I can't see it on the scene neither move it by dragging (it's like it was behind the cell's content view). May anybody help me?
It's a very weird behavior... I'm getting crazy!
I'm not sure if is the same problem, but I had problems editing statics cells when there are many. So in the size inspector of the view controller I set the simulated size to "freeform" and increase the height to unreasonable levels (2000), and then I can access the bottom cells.
Here a screenshot.

Have a UITableView extend its footer beyond its height?

I have a UITableView at the bottom of the screen that pulls up and then snaps back down. When it is pulled up, though, you can see the view behind it because the tableview's height is finite and less than the size of the screen.
I tried using a large footer, but that affects the snap-back of scrolling the table up.
I also tried setting a fixed height for heightForFooter and returning a large view from viewForFooterInSection, but that view gets cut off after it reaches the height returned by heightForFooter
How can I display fixed content beneath my table without affecting its scrolling?
Add a background view to your table view, and then add a subview to that view with the color you need. You can position the subview around table/section headers.
In viewDidScroll, update the y position and height of the subview.

UITableView with a UIView underneath the Cells

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.

Resources