UICollectionView inside of UITableViewCell - AutoLayout - ios

I'm using a UICollectionView inside of a UITableViewCell. It's all working fine, but i have some issues with Auto Layout. The UICollectionView should just show the cells without horizontal or vertical scrolling.Because now I have a the scrollable UICollectionView inside my UITableViewCell the following code doesn't work for me to get the dynamic table cells' height for this cell, but for other cells.
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44
I unchecked the option "scrolling enabled" in storyboard, but the result is, that i just can't scroll and don't see the rest of my collectionView.
Right now I simply set constraints from my UICollectionView to the UITableViewCell to all edges, but it's not working.
Would be great if someone have an idea.
Thanks a lot.

You'll need to have a height constraint set on your UICollectionView. If you've just pinned your UICollectionView to your UITableViewCell, it's getting its height from the table cell and the table cell is getting its height from the collection cell, so neither really knows what to do in that situation.

I did meet a similar issue before. It turned out that I haven't fully set up the relationship between the UITableViewCell and its containing elements so that they don't know how far to grow. I don't think this is related to embedded scrolling view. Just make sure that you have constraints set up between the UI elements inside the UITableViewCell and the bottom of UITableViewCell.

Related

UITableviewCell Dynamic Height Programmatically with the use of UITableViewAutomaticDimension

Hi Guys here i am suffering issue of dynamic height of UITableview Programmatically. I have set Autolayout of all view without any error
but lblDesc (UILabel) not expand with its size according to content. plz guide me
sometimes I do not need btnVideo (UIButton) so i have to hide btnVideo(UIButton) and dynamically all social networks UIButton come after lblDesc (UILabel)
Here i attached my code with only one view
UITableViewAutomaticDimension
https://drive.google.com/file/d/0B5mabdphYDhzWG9UMzM2MTV6cms/view?usp=sharing
You should use UITextView instead of UILabel.
Btw, never forget you setup constraints between text view and container views for all edges correctly, so according to your text size, the whole cell will be resized dynamically.
I have reviewed your code. tableview has correct setting.
Just setup correct layout constraints so that table view could know how it should change the height of cell.
Cheers

UICollectionView Update Cellsizes after changing constraints

I am using autolayout to determine the cellsize (fixed with, variable height) and set all the necessary constraints in the storyboard. Autolayout works fine as long as I don't change the constraints.
But at Runtime I have to add buttons to some cells. I remove the bottom constraint of the last label, insert the button and add a constraint to the label above, one leading constraint to the cell and one to the bottom of the cell.
The problem is, that the cells size is not updated after this. I tried to call LayoutIfNeeded in the cell and in the collection view but that did not work. I think the constraints are set up correctly. The button appears at the right position but the cell just keeps the height for a cell without a button. How can I tell the CollectionView to update the cell sizes?
You could refer the below link probably you can get your answer with manually and automatically size of UICollectionViewCell.
How make a collectionViewCell auto size only by height?
==> You can either use the UICollectionViewFlowLayout method itemSize property to set the UICollectionViewCell size, or use the delegate method, collectionView:layout:sizeForItemAtIndexPath: if you need to dynamically set the sizes of the UICollectionViewCells.

How to set Multiple Size/Merge cells in UICollection View

I want to make a layout using UICollectionVIew. But I am not sure it is possible or not.
I have tried changing height of one Cell but it is not working. Here is the layout which I want to acheive:
In this Layout height of each cell is fixed only the height and width of first cell is different.
How can I achieve this.

iOS 8+ - UITextView Not Stretching Vertically in UITableViewCell

I am using Auto Layout and have a UITextView in a UITableViewCell. The UITableViewCell's height is calculated automatically based on the constraints. Here is how I am specifying that the cell should be self-sizing:
override func viewDidLoad()
{
...
// Set the estimated row height
self.myTableView.estimatedRowHeight = self.myTableView.rowHeight
// Set the height of the cell row based on its constraints
self.myTableView.rowHeight = UITableViewAutomaticDimension
// Prevent extra rows from displaying
self.myTableView.tableFooterView = UIView()
...
}
I am certain that all of the constraints (leading, trailing, top, and bottom) are set properly on all of the UI elements on my UITableViewCell, but for some reason the UITextView is not stretching to fit its available text. I've tried reloading the layout and the constraints in the cellForRowAtIndexPath and the willDisplayCell methods to no avail.
If I scroll down on the table and then scroll back up to a given cell, the UITextView DOES indeed stretch properly. But upon first load of the view, it is not acceptable for some of the text to be cut off.
I've tried just about everything I can think of, and I cannot get the UITextView to stretch. Even stranger, I made a test app, the UITextView did stretch properly. It's not working on my app for some reason, though.
I'm pretty stuck and could use some help. Any help would be greatly appreciated!
I found out that my UITableViewCell had a Disclosure Indicator accessory. All I had to do was remove the accessory (set to None), and everything is working great! I'm not sure why this works, but it seems like it's a bug. Self-sizing cells should work regardless of whether or not there is an accessory on the cell.
Note
This bug appears to have been fixed in iOS 9+. For apps that need to support iOS 8, I would recommend removing the accessory from your UITableViewCell and replacing the accessory with a custom image.

Swift: UITableViewCell size to width of parent UITableView with autolayout enabled

I'm experimenting with autolayout and am running into trouble with UITableViewCell since they're created at runtime. My cells are loaded from a xib from the main ViewController. This xib has View mode set to Aspect Fill.
I've read about different ways to do this online and have yet to get any of them working. What's considered the best way to handle this?
It looks like your constraints aren't set properly, as the cell is shorter than the image's height.
Using AutoLayout and self-sizing cells is the easiest way to handle what you want to do. Once your constraints are setup properly for your custom cell, tableView:cellForRowAtIndexPath: can call dequeueReusableCellWithIdentifier:forIndexPath: and all the subview layout will be handled for you.
See the detailed walkthrough by smileyborg in his answer to Using Auto Layout in UITableView for dynamic cell layouts & variable row heights.
He also provides workarounds for the minor issue with the initial cell width being based on the storyboard cell, instead of the tableView width. I worked around it by setting the cell's initial width to the tableView's width, as Rasputin had suggested.

Resources