ios 8 nested auto sized tables - uitableview

I'm pretty new to Auto Layout, so this may be an easy question to answer. I have two UIViewControllers which both contain UITableViews that need to auto-size their cells. I'm trying to use Auto Layout and the new iOS 8 auto-sizing table cells. There is a parent/child relationship between these tables: the parent table view will display the child's table view in its cells.
The child's table view seems to auto-size just fine (the cells at least). The problem is that the parent cell seems unable to determine the size of the child table view.
What I see in a debug session is that the parent cell appears to be truncating the child's view. To be more specific, when I inspect the view hierarchy, I can see that the child table view's cells are auto-sized correctly, but the child table view seems to be set to the size of the parent cell (or some sort of default value) and not to its contents.
I have a repro project that demonstrates the problem. I think it may have something to do with UIScrollView and Auto Layout. I've read other posts on this topic which seem related. If that's the case, I need a little help figuring out how to apply that to my repro project.

Related

How to properly set up constraints for collection view inside of table view cell (in Interface Builder)?

So, I read this stack discussion on the same topic but I didn't really find a solution for what I'm trying to do (or none of the solutions worked for me). I've embedded a collection view inside of a table view and set the labels and such accordingly (with correct values, as I've tested by printing labels.text in the console). However, it appears the collection view is automatically sizing my cells to 50 x 50 (defaults), hiding the labels (see image).
I have automatic sizing off, estimate size set to none, and to the best of my knowledge the constraints in the collection view cell do indeed define its size. I tried setting all the heights and widths manually, which appears to do nothing (though it does work for tableview.rowHeight, which for now I've set back to auto sizing as the cell remained 50x50 inside the 325px height row). Any advice is appreciated!
IMG: what the UI is supposed to look like
IMG: what the UI looks like
IMG: collection view cell constraints
IMG: table view attributes
IMG: table view attributes 2
IMG: collection view attributes
IMG: collection view attributes 2
IMG: table view code
I've done my best to include all pertinent information. Please let me know if more is needed.
There are a handful of solutions to this problem. For me, it was setting the cell size in the attributes editor for the collection view (and in the attributes editor for the collection view cell), while leaving everything with the table view on automatic. The only unfortunate consequence is that the table view row height automatically sizes to the collection view height that you manually set with constraints in interface builder (without said constraint, the table view has no height to go off of). This isn't a problem for me, but it depends on the project.

Choppy/Laggy scrolling of Collection View with Dynamic Content

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.

Resizing UITableView with a table header in UIScrollView using auto layout

I have one simple UIView and three tables nested in the UIScrollView. The first two tables have table headers included. The third (orange) table has no header view and it is resized correctly according the data it uses. The picture displays the closed state of the scroll view. UITableView_A and UITableView_B are closed, UITableView_C opened. The data are ready for use in all tables, and also the cells are being created.
Also in xib I have connected the layout constraints to the properties from the subclass of UIScrollView. The constants are specific sizes as UIScrollView demands it for its nested views.
The issue:
The views are being resized correctly but when I update the constants for heights of the tables without the header views (the first two tables, green and pink) I manipulate only with the header views. Which is odd. The auto layout constraints for the green and the pink table are setup correctly in the xib file. I was checking the resized tables in the simulator using introspection tool and I realized the first two resized tables are not tables BUT only the header views.
The height of cells is 44 and headers also 44. The tables are not scrollable.
Closed state:
Opened state
When I update the auto layout constants related to any table I call this line afterward
[self layoutIfNeeded]; //(scroll view)
UPDATE 1:
When I remove the header views from the tables, then the resizing works perfectly for the tables. I am really curious why I manipulate just with the header views instead of the whole table when the constraints is defined on the table view NOT on the table header view.
I replaced the table header views with the section header views and the resizing works smoothly. I'd be glad to know the explanation for the previous problem.

How to dynamically resize table views inside a scroll view

I want to display two table views inside a uiscrollview and make the table views resize dynamically to fit their content. The table views should not be scrollable, hence the embedding in a scroll view. I have managed to resize the scroll view appropriately. The setup is as follows:
UILabel1
TableView1
..some extra space..
UILabel2
TableView2
I suspect that this should be possible with auto layout, but I need help to get started (I'm new to auto layout). Furthermore, I know that the labels could be added to the headers of the table views, but for now this will do. The data is fetched asynch over a network connection, so the table views need to be updated when the data is in.
Optionally, a couple of spinner could occupy the table view space until the data is ready to be displayed.

UIcollectionview decoration view VS supplementary view

I'm starting my development of an ios app using ios 6 and UICollectionView.
I've noticed there's support for both supplementary views and decoration views.
Can someone please explain in bullet points the difference between the two? They sound very similar.
If I want to add a loader to my collection view (that will appear at the bottom of each section, while the section is loading) should it be a supplementary view or a decoration view?
Thanks
Decoration views are just what the name says: decoration, chrome. Only the collection view layout decides what they are and where to put them (for instance, if you want to draw lines on the screen every 5 items).
Supplementary views are more related to your data. The collection view layout still decides where to put them, but they are provided by the collection view data source, just like regular cells. For instance, if you wanted to put titles for sections, you would use supplementary views because the title would be different for each section and you need to call the data source for each.
If your loader is generic, it could be a decoration view, however decorations views are not really accessible (the layout object says where to put them, and that is it, they are created by the collection view and you never get a reference to them), so if you want to start/stop animating it, a decoration view is not the best choice. If you use a supplementary view, then you have access to it at creation time (in your data source collectionView:viewForSupplementaryElementOfKind:atIndexPath: method). However, you can only query the collection view for regular data cells once they are laid out on screen.
Also, you will have to write your own UICollectionViewLayout class if you want to use custom decoration or supplementary views. The base UICollectionViewFlowLayout only provides for a footer and a header supplementary view.
from UITableView perspective :
Supplementary = sections.
Decoration = tableFooterView tableHeaderView

Resources