TableView and CollectionView in one ViewContoroller - ios

I have UITableView and UICollectionView in one ViewController.
If CollectionView is below the TableView in a hierarchy, the scrolling and clicking work only for CollectionView but for TableView all interactions are not working at all and vice verse...
On the screen, there is only one visible element TableView or CollectionView, and it's controlled by isHidden = true/false
What is wrong have I missed? How to have both TableView and CollectionView scrollable/clickable and manage that which is visible on the screen?

You need to manage isHidden for containers like
container1.isHidden = true / false
container2.isHidden = true / false
tableView/collectionView are just subviews of their containers so hiding/unhiding them doesn't make the ability to interact with back-most one

Related

UICollectionViewCell content overlapping other cells

I'm trying to display a UITableView inside a UICollectionViewCell, that would be displayed over the other cells.
(The other cells don't have a table view)
Here's what I get so far :
Result : The UITableView is displayed behind the other cells.
I've set clipToBounds = NO to the content view of the cell, so that the table view gets displayed outside the cell content.
After looking at the View Hierarchy inspector, it seems that the cell containing the table view is lower than the other cells. I think it should be on the same level ?
Any help would be appreciated, thanks !
I found a solution that is working for now :
self.layer.zPosition = 1000;
(Inside UICollectionViewCell)

What Kind of scroll view to contain 2 tableviews and collectionview

I have complex view that contains Image slider(collectionView),List of offers(tableView) and List of Services (TableView), The main Content View should be scrollable and all subviews should not be scrollable.
I tried to make the parent view UIScrollView but i got a problem that when the first tableview items exceeds the screen limit its not showing the exceeded elements.
I tried also to force full tableview height but i had a problem with scrolling
self.tableView.frame.size = CGSize(width: self.tableView.contentSize.width,
height: self.tableView.contentSize.height)
Is there a way to force showing all the tableview elements ,or should i use another type than UIScrollView?
Here is an image for what i want to display
For this you need to disable your UITableview scroll like:
tableView.scrollEnabled = false
then all you need to get count of tableview element multiply it by the height of your tableview cell and set that height to tableview like:
tableViewHeight.constant = count * z
Where z is height of tableview cell.
All set now.

How to add a view as a subview of UITableViewCell but on top of all other views

I have a question - how to add a view as a subview of UITableViewCell but on top of all other views?
Here is an example of what I'm trying to achieve:
The image should scroll with the cell - save it's position relatively to scroll view (table view in this case).
If the cell is to small in height then the emojis overlay will be cut by the cell on top of current one, so how can I add this emojis overlay as a subview but at the same time display it on top of every cell? I've tried bunch of variants for now and nothing is working for me.
Just adding as a subview of the current window is not working for me because this overlay should scroll with the cell.
Tried code:
view.layer.zPosition = 5
cell.contentView.insertSubview(view, aboveSubview: cell.contentView)
cell.contentView.bringSubview(toFront: view)
UIApplication.shared.keyWindow?.addSubview(view)
Try to set cliptobouds = false for your cell.contentview and cell itself.
Otherwise if it is single overlay which you want to be on top of every cell then better implement UISrollViewDelegate and position the overlay accordingly.

CollectionView cells appearing outside collectionView.

I have a collectionView laid out in the storyboard like so:
Note the constraint: Collection View.top = Search Bar.bottom
I don't want any of the content in the collection View above that line. However when the app runs and you scroll the collectionView, this is what happens to the cells. What could be happening here?
Probably collectionView.clipsToBounds = true

UICollectionView cell is disappearing when dragging out of initial bounds (Swift3, CollectionView, Drag and Drop)

I have a problem, when dragging cell out of initial bounds.
On drag, I take value from UILongPressGestureRecognizer location and set cell "center" property to this location.
The problem occurs when I scroll down, below initial bounds, the cell doesn't show on the view (although there are cells existing down, probably loaded after first view appearing). When I scroll little up, within same take (press), cell shows up again.
I tried several things
cashing cells, so view alway get the same cell instance on reload
override func viewDidLayoutSubviews which lead in endless loop
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
myCollection.collectionViewLayout.invalidateLayout()
}
collectionView?.clipsToBounds = false
None of these worked for me. Could you help me? Thanks!!!

Resources