How to make a particular static cell in UItableview self adjusting according to the constraints of the contents inside it - ios

I've done some research on self adjusting static cells but they seem to apply to the entire table view as a whole.
what if I'm only interested in targeting a specific cell like the picture below? How do I go about doing it?
edit: What I intend is for the tableview cell to expand when the collectionview gets populated with more cells. Thus allowing the entire page to scroll accordingly.

Are the images in the collection view always the same height ? If the images in the view are a static size, you could just divide the number of images, by the number that will fit on a line. Then multiply that by the height of the lines to set the tableview cell height.
This might be helpful:
Dynamic Sized Tableview Cells

Related

Collectionview inside tableview cell with dynamic height cells and dynamic content swift 4

I am working with collectionview inside tableviewcell in Swift 4. I get the content from server which is all dynamic. I have to show different types of collectionview behaviours.
For example, in the first tableview row should be collectionviewcell with screenwidth and scrollable. In the second row, collectionview with 3 sections and each section has different content different number of items.
Here I got stuck I am unable to show 3 sections one below other it is showing besides horizontally. I have calculated collectionview flow layout size.
Also in last row I have collectonviewcell with scrollable content,here when i scoll the content is repeating from bottom row or top row. I want the smoth scrolling and to stop repeating the content.
I am new to Swift. Can anybody help me out of this . Thanks in advance.
The smooth way is to create tableview with its cell xib and inside its cell add collection view and create another xib for collection view cell. This method is helpful when accessing collection view for different tableview cell. Rather using without loading Xib's may mixup your code.
You have to set tableview cell height as UITableViewAutomaticDimension. This will handle your cell height as per your dynamic content.
For each tableview cell you have to set collection view's property by using cell's index path as per your requirement.

How to scroll the UICollectionview from particular cell

I have a collection view. I need to scroll only cell4, cell5, cell 6 so on. First two cells are remain same. Is is possible using only UICollectionview. How to achieve this.
FYI: the height of the cell is more than the screen height.
One of options would be to subclass UICollectionViewLayout and update frames in attributes of first three cells every time when scroll offset changes. So the cells would look static.

How to get height of UITableView placed in another UITableView in Cell as childViewController

I'm struggling with wired kind of problem. I have UITableView with one cell. This cell is only holding containerView with childViewController (second tableView). My problem is that, first tableView(parent) must have UITableViewAutomaticDimension row height but it doesn't work (It dosen't know correct size of that cell with second tableView).
How to get correct size of second tableView) ?
Second tableView (inside Cell) have scrollingEnabled turned off (tableView.scrollEnabled = false), first tableView must have correct size of second tableView in order to provide correct scrolling experience.
Since a UITableView inherits from UIScrollView you can use the contentSize property to get this information. This is how the scrollbar works on the side.
I have done a similar thing before (long ago), so the following is somewhat hazy/ irrelevant/ unessecary. There might be some gotchas with unknown/unrendered cell heights in the embedded tableview. I rememeber having to set the tableview height to a large number (forcing all cells to render) fetching the contentSize then resetting the tableview height to the contentSize.height.
Are you shure you really need second table view? If you have just one cell probably you don't need it. I recommend you to calculate table view height as the summ of it's cells heights. If cells of embedded table view have constant height it could be simple. In other case you also could calculate cells height.

What should I do to set up the constraint on UICollectionView

I have a tableview which shows the news. And there's a UICollectionview inside each UITableview cell. Also there'll be some images inside collection view cell and the number of cells cannot be fixed because news may contain one image, two images or more.
The
UITableview cell looks like the following structure :
xxxxxxxxxxxxxxxxxx
name
news info
(UICollectionview img1 img2...)
UIButton and UILabel (such as like, dislike, comment..)
xxxxxxxxxxxxxxxxx
and I also set up the constraints. And I have to set up the width attribute for the UICollectionview. The main issue is that no matter how many images I may have for the news, the collection view will be always that wide and will block the click event for the tableview cell. So any ideas for that,
thx!
here is a suggest:
set the initial width constraint to 0, then changing it to actual width when bind data to cell.

UICollectionView: Reordering cells of varying, but fixed widths

I am trying to build a UICollectionView that consists of cells that are of fixed height and varying widths. The cells can either be 100%, 50%, or 25% in width.
I am creating these cells from a custom subclass, and then I am adjusting the size in sizeForIndexPath. My problem is that when reordering cells, I get a lot of weird visual glitches as the cells have their sizes adjusted rapidly as the index path changes.
Basically, I want the size of the cell to depend on the type of cell (or the content in the cell), not the index path of the cell.
What is the best way to handle this? I thought about using multiple classes for the different types of cells, but I can't set the width of the cell with a frame when initializing it. Any ideas?
Update: Here's a link to a video showing the bug I am trying to solve
http://d.pr/v/FTM8+
Try this tutorial. It for a table view but in the conclusion some recomendations for a collection view. I cannot try this tutorial now and garaunted it works for collection view but tomorrow I will do it.
Cheers.

Resources