UICollectionView as a subView of a TableViewCell - ios

I need an advice for a thing I want to implement for an iPhone application.
Actually what I want is to have the ability to dynamically populate a TableView with a specific template delivered by an engine (is it clear ? ...)
For that I want each of my TableViewCell of the TableView to be a UICollectionView.
For example :
I want to display an image, a title and a subtitle in my cell (I know I can do this by using a UITableViewCellStyleSubtitle, but when I have more complicated things to display it won't work with it).
For that, I want a UICollectionView with 2 columns and 2 rows on each column. The first item (image) will be placed on 0,0 with a 2 colSpan (to take the whole column). The second item (title) on 1,0 and the third item (subtitle) on 1,1.
I also want the collection view items to be sized correctly.
So 2 questions :
1) Is it a good way to work with a UICollectionView, or is there simpler ways ?
2) How can I specify rows and columns, along with colspan and rowspan in a UICollectionView ?
Thank you very much for your answers :)

A collection view is overkill for this. Just define a cell with custom subviews. You can resize them if required when the cell is populated. You haven't said what the most complex or simplest layout will be so I can't offer any more specific advice.

Related

UITableView cells on the same row

as I say in the title, I'd like to display two or more cells on the same row. I have every cell with a UILabel inside. The labels can have changing width depending on user's input. I'd like to fill a row with many labels as I can. Can someone give me some advice on how to do it? Thanks.
Short answer: You can't. Slightly longer answer: Use a collection view.
Table views are designed to show a single column of cells.
You can't make a table view contain multiple cells in a row.
You could probably create a view controller that had side-by-side table views inside it, but it would be awkward and hard to use, and the table views would scroll independently of each other.
If you want multiple cells on the same row, you want a collection view. A collection view is similar to, but more flexible than, a table view.
I would consider using a horizontal UIStackView to achieve what you're trying to do. Depends on how dynamic and changeable you need it to be.

Best approach to achieve this grid layout on iOS

A question for the UICollectionView experts.
Imagine a collection view that looks like a table view (full width cells), and when you tap on one of them, new cells are inserted underneath that cell that are square cells, say half the width of the collection view, in 2 columns. Tapping the header again would appear to collapse the section.
Keeping in mind that I’m trying to use UICollectionViewFlowLayout instead of a custom UICollectionView.
Would you:
A) implement the tableview style cells as collection view supplementary views (headers), with a gesture recogniser that inserts the square cells?; or
B) implement the tableview style cells as one cell type, and the square cells as another cell type?; or
C) something else?
Personally I would go with option A. In the situation you're describing the full width item is really a section header that's function is to show/hide it's sections's cells.
From a data structure standpoint this is much easier to maintain with this approach. It can be handled with an array of arrays.
If they were all cells it would most likely be one large array, and would be more difficult to make the distinction between a full width cell and the half width cells.

How to make an effect of expandable UICollectionView cell in iOS

I have a collection view 3x3.
Item (collection cell) contains some icon and label.
I want some additional text to be shown inplace when user touches the cell. The view with this text must be fullscreen width.
In other words I want to insert a view with text between collection rows. It's desirable that the view appears with animation.
How should I do that? The first ideas I've got are:
Divide CollectionView rows into sections and use section footer for this purpose. Make this footer of zero size and show it when needed.
Dynamically create full-width cell and insert it at the end of the row where selected item is located.
Both methods seems tricky to me. Maybe there is more straight forward way?
Any ideas? Thanks!

Add a list to a UITableViewCell

I'm trying to add a list within each tableview cell that will go to the right of an image. Each list may create new items and remove them. Each item is it's own textView that will show all of the lines. I want the cell to be able to resize itself based on the height of the list.
I've tried using sections but I want the header to be to the left of the list, not above.
I've looked at trying to make each UITableViewCell it's own tableView and put the list in there. However, I think it will be difficult to determine the size of it since some list items will be more than one line.
I've thought about adding stack views to help with the dynamic resizing of the cell.
Is there a good way to do this? Is there a different approach?

UICollectionViewFlowLayout sections as columns rather than rows

I'm trying to create a UICollectionView of two columns (of potentially different lengths) with the property that when a cell is deleted the cells below (rather than the cells to the right) move up to take its place. I have considered customising the layout using layoutAttributesForElementsInRect etc but don't want to do this if there's an easier way.
Basically all I need is the transpose of the standard FlowLayout with each section a new column instead of a new row. Any advice would be much appreciated.
It is not possible using UICollectionView without customizing the collection view layout based on your needs. UICollectionViewFlowLayout is a line breaking layout that means, it places all your cells along a line and break that line to the bounds of the collection view one by one. So you can place two cells in a row by adjusting the cell size and section insects. Even though it wont allow you adjust the cell during the deletion as your need. Obviously the adjacent cell will take place the position when deleting a cell. Can you go with two collection views side by side instead of one??

Resources