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)
Related
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.
I have project with structure like:
-scroll view
--view
---collection view
----collection view cell
-----table view
------table view cell
This structure is necessary for this project.
Every things works correctly like scroll view, collection view and table view but there is interaction just with index 0 in collection view.
In other words didSelectRowAt method just call in index 0.
And i have uploaded my project on GitHub:
https://github.com/reza-khalafi/ScrollCollectionTable
Please help me to fix this problem.
Thank you
To fix the offset try using an auto resizable cell for UITableView
so in setTableViewDataSourceDelegate method just call
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300
In a tableview one cell overlaps the cell displayed under it when initially presented. When you scroll down until the top cell is not longer visible and then scroll back up the cell are ok again.
I deactivated the separators with this line:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
The second cell has a view that fill it from top to bottom, that was a border radius. When the cells are initially presented the border is covert.
How can i fix the spacing of the tableviewCells when they are initially loaded? Can i set the z index the second cell, so that the second cell is above the first one?
I finally found that the constraint of the the top cells where causing the trouble. I found a workaround by storing the layout constraint in a property and adjusting the constant of the constraint as needed.
For "Can i set the z index the second cell, so that the second cell is above the first one?"
UITableViewCell is subclass of UIView so in table view delegate use this :
secondCell.layer.zPosition = 1;
Context
I am trying to create something similar to a Table view using UICollectionView.
I am using Xcode7 and storyboarding.
The way I do it is that I drag the collection view across the entire controller view.
And then I drag the entire cell across the row and align it with the right and left boundaries.
Problem
But, when I place a label inside the cell, then it gets displayed correctly only when the device is in a horizontal position.
When the device is vertical, it gets cut off at the left boundary.
Question
How do I ensure that the width of the collection view cell matches that of the container width?
1) Implement the function of cell size and return the collection width:
-(CGSize) collectionView: (UICollectionView*) collectionView layout:(UICollectionViewLayout*) collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*) indexPath {
CGFloat height = 50; //set the wanted height
return CGSizeMake(collectionView.frame.size.width,height);
}
2) Reload the collection when the screen size change (i.e. orientation change).
It is because you are not using autolayout. You can achieve this entirely in storyboard or through code.
Using Storyboard
Add UICollectionView in your UIViewController in storyboard.
Drag UICollectionView to fill up in your UIViewController.
Add Constraints as shown in image.
Drag UICollectionView to fill up in UICollectionView.
Add UILabel (Or whatever you want to have in cell). Also add constraints in that element.
Build and run.
I have the following View structure:
This view contains a main table with cells. Every cell of main table contains a label 'Point' at the top and a small subtable. When user clicks on the cell of main table, cell should expand to the bottom and the small subtable should take the free space.
I'm changing the size of main table cell using a flag in the heightForRowAtIndexPath method e.g.:
if (selected ...) {
return 100;
}
return 30;
This works fine. The problem is in resizing subtable. I tried to use margin constraints (bottom one from the cell content view and top one from the Point label), but in this case table does not appear at all :)