I'm trying to make self resizing cells for my collection view. Ill display text parts and those text parts have many sizes, since every cell will have a paragraph. Reading a guide on appcoda and useyourloaf i got the solution to make it with table view, so the only thing i can't do on the collection view cell is this
self.tableView.estimatedRowHeight
for obvious reasons I can't use it on collection view. Is there any similar thing that I can do for collectionView cells?
PS: I can't change the collection for a tableView.
PS2: I'm using swift
In theory there is; Apple has been claiming since WWDC 2014 that there are self-sizing collection view cells in exactly the same way as for self-sizing table view cells.
But in fact every time I try this feature, my app crashes. So in my view the answer is: no, if you want dynamically sized collection view cells you will have to size them dynamically yourself. This is not difficult, however. Just implement collectionView:layout:sizeForItemAtIndexPath: and set the size of the item. If you want it to be based on internal constraints, call systemLayoutSizeFittingSize: here.
Related
I want to place a view between cells in a collectionView. Like an ad. to be added dynamically after they see the first 3 cells. Is there a method to do that?
If you could figure out a way to do that you still shouldn't. A collection view owns the area it draws in. It's in charge of placing cells where they belong within it's content view, and you are supposed to keep out.
That said, collection views are extremely flexible and you could design your collection view to display a set of "normal" cells, an ad cell, and then more normal cells. If your ad cells are different sizes or need to be spaced differently than your normal cells then you might have to create a custom collection view layout.
No, you can't. But you can add a UICollectionViewCell which will contain advertisements or something else you want to be added. It is really simple. Just create two prototype cell. First cell will contain your data, second one will contain some extra data.
I have to make a grid with a specific architecture.
I don't know if I have to use a stackView with views? Or a collectionView with cell?
Let's see my image :
Green cells will be repeated infinite times.
Thanks for your help!!
The easiest and best way do make this is collection view, Also in collection views cells(items) are reused, so you don't need to release them after they have disappeared.
It depends on the number of grid cells. If the number of cells is 2~4, it's OK to use stackView.
But
Green cells will be repeated infinite times.
So, you should use collection view. Collection view is suitable for displaying repeating layouts like your image or calendar app on iOS.
And offscreen collection view cell(table view cell also) is reusable, so you only create cells enough to fill the screen and a little more.
See Table View Cell Reuse Explanation
Looking for advice from more seasoned IOS dev's. I'm building with swift and autolayout storyboards. I have a cell within a table view that displays a picture and comments.
My problem is that any picture can have zero to several comments. I would like to limit it to two but I am now looking at having a tableview within a tableview cell. My other approach was to just add two comments and set the height to zero if comments for that picture have not been made yet. I started down the tableview within tableview (tableview inception) approach but shifted thinking that Apples autolayout would just pull everything in tight. Sadly tableView.rowHeight = UITableViewAutomaticDimension Turned out to be a layout nightmare and never did work right inspite of my carefully placed constraints. Am I missing a third obvious option. What would be your approach?
You can use view based NSTableView with 2 NSTableCellView.
PhotoWithComments NSTableCellView
WithoutComment NSTableCellView
I think using view based NSTableView would be easy then cell based NSTableView for your problem.
I have a UITableView and one of my table cells is a UICollectionViewController subclass that contains a UICollectionView of displayed email addresses. When a user adds an email the UICollectionView and it’s cell in the table view should get taller.
I’m currently attempting to do this setting my collectionView height constraint to collectionView.contentSize.height in the LayoutSubviews method of my collection controller/cell class. My issue is that the cell in the UITableView is not changing size when this happens.
I am assuming that this is because there is nothing telling the table view that the height of the email entry cell has changed. I am currently using dynamic cell sizing - or trying to anyway. Even, if I call tableView.reloadData() this still does not work. I’m wondering if someone could give me a high-level idea of how they would set this up.
UPDATE:
I had a broken constraint issue that was part of my problem, but this is still not solved. While have proven that I can update the height constraint and that will update the size of the collection view, it's out of sync. It's always one update behind. Here's an image showing the 'UICollectionView' in green and you can see in the logs that I'm updating the constraint (yes, multiple times) each time after adding a new item to the collection, but it is not updating the bounds of the view instance. In this example, if I were to add a new item to the collection, the next time I inspect bounds.height it would be at 149.5. What am I missing!?
i had answered this question in another tableview inside tableview cell that will work for collection view too ,i explained it in this thread
ask me if you faced any problem
It seems you want to set the height of your table view cell dynamically. This detailed tutorial walks you through making a custom cell class that will have dynamic height. Unfortunately, this tutorial only walks you through how to do this with auto layout constraints and a storyboard. In the tutorial you'll notice that the height of the cell depends on the constraints put on a title label within the cell. Try doing the same thing, but applying the constraints on the content in your cell (the collection view cell).
http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout
I am having a problem where my collection view scrolling becomes very choppy/laggy as I get more and more cells. The screen contains a list of messages and comments for the messages, so every single view is dynamically sized. I have a bunch of custom layout attributes which I apply to handle laying and sizing everything.
I apply the custom attributes to the cells by overriding applyLayoutAttributes: and then calculate all the subviews frames from those.
I already cache the calculated sizes of cells but it is not enough.
I assume that there are some techniques people use to address this problem, like caching layout attributes, or somehow preventing the need to layout a cells subviews everytime cellForRow is called?
I assume this is a common problem since it is a problem I have faced with literally every table I make with dynamic content? I would appreciate any ideas :)
P.S. Rasterizing the cells doesn't help.