Tableview within a tableview or autolayout nightmare - ios

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.

Related

TableView and CollectionView in the same ViewController with Swift

I'm building my application with Swift and I want to set up TableView and CollectionView in the same ViewController.
The only answer I founded is to setup my CollectionView in the TableViewCell of the TableView.
I did it but it scrolls separately.
The solution I found is to disable CollectionView scrolling and then configure CollectionView's height constraint programmatically by summing heights of the cells. It isn't perfect at all because cells become non reusable (250+).
I'm in desperation because I have seen this setup in many other apps and I think that answer is so simple but I can not find it anywhere.
Can anyone please help me? Thank you a lot!
Another option is to set it up as a single collection view with two sections, one that looks and lays out as a tableview and the other that has the more collection view appearance.
Or set it up as a single table view with two sections, one of which displays two side-by-side images per line (this is the old school way of creating this layout.)
Lots of ways to go about it, depending on what you want to play with and what you want to learn :)
You can put a UITableView and UICollectionView inside a UIViewController, and implement UITableViewDelegate, UITableViewDataSource and UICollectionViewDataSource.
Keys:
Use AutoLayout to make sure tableView has only two rows, and
collectionView takes the rest of area.
Make sure tableView.scrollEnabled = false
Here is a sample, https://www.dropbox.com/s/v6yc40udfk8mqx5/FlexTableCellHeight.zip?dl=0
Set up a blank ViewController. Then place two ContainmentViewControllers inside of the ViewController. Size them however you want based on how much screen you want to the be tableview and how much you want to be collectionview. Then create segues from each containmentViewController to your tableviewcontroller and collectionviewcontroller using embed. This will allow both to be on screen at once and scroll separately.
If you do not need to use a TableViewController and can get away with just a tableview you can also just place one containmentviewcontroller below your tableview and create the embed segue to your collectionviewcontroller.

UICollectionView that functions like a tableview

The designer came back with a layout that displays information differently.
Is it possible to make my UICollectionView function like a UITableView? Where each cell takes up one row and there is only one column?
Everything I found on the net seems to be about the opposite, making a UITableView be a UICollectionView
Actually, its very simple. Just make the width of the UICollectionViewCell equal to the width of the view.

Is there a "self.tableView.estimatedRowHeight"like method for collection cells?

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.

Customizing / subclassing UICollectionViewLayout to enable scrolling in multiple directions

I'm designing a layout for my app that is going to take advantage of UICollectionView. I have created some moderately complex collectionView-based apps before, but I may need to subclass the layout class for this one. The main point I'm trying to figure out is whether I can have different sections of the same collectionView scroll in different directions.
Based on what I have read and tried so far, the only way to have one section scroll horizontally and another vertically would be by using multiple nested instances of UICollectionView.
This is a basic idea of my layout. My guess is that even with subclassing, a single UICollectionView would not be able to handle it. Or would it?
I think you could do it with a custom UICollectionViewLayout but I'd use the default flow layout with one cell containing something like a SwipeView for the section 0 and other cells in your section 1.

Changing frame of one of two sections of UICollectionView - ios

I am trying to configure my CollectionView to have one section be differently sized than the others. I have two sections. Lower part should show a number of cells simultaneously and the upper section should only show one cell at a time but be scrollable to reveal more cells one by one.
I tried to play with the .frame property of the CollectionView but obviously it is not the right approach as it changes the appearance of the whole view.
I also tried to retrieve the FlowLayout object and see if I can get it from there. Did not find a way.
Neither the section Insets are the answer so far ...
It is simple to use two uicollectionviews for upper and lower section, instead of using only one.

Resources