How to set the height of prototype cells in an iOS table views - ios

I have a table view with a prototype cell containing both disclosure and detail accessories. I want to use a font size of 12 in the cell and reduce the row height accordingly. Thus the size of the two accessory icons need to be reduced in size as well. I assumed this would be one of the more obvious things one might want to do with a table view but fail miserably in figuring out how?

Assuming you are have a nib or storyboard, you should see a resize handle on the cells when you select a cell in the editor. Just grab and resize.

Related

UICollectionViewCell loaded from Xib (Nib) is being covered by storyboard cells as its size is not updating

I'm using a Xib file to hold a UICollectionViewCell item that I do not want to have in a Storyboard. I have the UICollectionView set to calculate its cell sizes automatically. But what I see when the collection view loads is that it's retaining the default 50x50 size for the cell that's being loaded from the Xib file. It's not being updated to the size it is showing up as.
The cell looks correct on screen and at the correct size. But when another cell loads that is contained in the storyboard it's loading on top of the other cell as its being placed 50 points down from the first cell.
The cell outlined in orange is the one being covered up by the one in green. I cannot show a larger portion of this due to work restrictions but I hope this clarifies what's happening.
I've tried to say that the cellNeedsLayout() and layoutIfNeeded() but neither of those make any difference. It's like the actual height that the cell is not being calculated early enough to have the collection view place cells around it correctly.
I've not been able to find a way to preload the Xib so that it already knows how large that needs to be. I am using a subclass of UICollectionView named CollectionCell.
Can anyone point me in the direction to look or suggest a fix for this other than moving what I've done into the Storyboard?

How to make a particular static cell in UItableview self adjusting according to the constraints of the contents inside it

I've done some research on self adjusting static cells but they seem to apply to the entire table view as a whole.
what if I'm only interested in targeting a specific cell like the picture below? How do I go about doing it?
edit: What I intend is for the tableview cell to expand when the collectionview gets populated with more cells. Thus allowing the entire page to scroll accordingly.
Are the images in the collection view always the same height ? If the images in the view are a static size, you could just divide the number of images, by the number that will fit on a line. Then multiply that by the height of the lines to set the tableview cell height.
This might be helpful:
Dynamic Sized Tableview Cells

Can I load a UITableViewCell directly from a xib with a specific size class or trait collection?

I'm trying to do the following in my iOS app:
Embed a UITableView into a parent scroll view; the table view will have its frame expanded to show all its contents (I need to do this because the table view data is a small component of a much larger more complex screen, and I don't want nested scrolling behavior)
I have different layouts for iPhone and iPad, so the cells in this table view are using size classes defined in a table view cell xib.
Since I want the content size of the table view to be accurate, I don't think I can use UITableViewAutomaticDimenstion as the rowheight, so I implement tableView:heightForRowAtIndexPath: and load an instance of my tableview cell from the nib directly and store that view as a property with which I can figure out how tall the cell should be according to autolayout.
My problem stems here; when I load the cell directly from the nib, on iPad the cell uses the constraints and layout in the 'Any' size class as defined in the nib, which is incorrect because the iPad's layout uses the regular width class only in my nib. This causes my table view cell heights to be wrong and too large in my case.
What I need to know is if there's a way to force the trait collection on the cell I load, such that the proper constraints for my views are used on each device type. I can't seem to find anything in the docs that allows for this directly in UIViews, only in UIViewControllers and I'm not keen on holding an offscreen UITableViewCell in a random offscreen UIViewController if i can help it. Any ideas?
After writing this I found this question: Offscreen UITableViewCells (for size calculations) not respecting size class? which seems to ask a similar thing, and the answer in there worked for me (add the offscreen table view cell as a subview of the tableview, or some other view that provides a trait environment). It's not pretty but it seems to work out.

Auto Layout in UITableView for dynamic row heights with table view cell from universal storyboard

So far I've had some success in calculating dynamic table cell layouts with auto layout. And so far, I have maintained different storyboards for iPhone and iPad. I would now like to consolidate them into a single storyboard per app. I'm currently stuck at a point where my height calculations do no longer function.
The trouble is apparently that the table view cell as dequeued from the storyboard is still at its fixed storyboard size (relative to a specific device, i.e. iPhone in my case) when the calculation is first required. It will be resized to fit the actual device (iPad in my case) when the table is displayed. But tableView:heightForRowAtIndexPath: is called before that and therefore does its calculation based on the wrong table cell width.
Is there a good way to solve this problem? It seems as if this accepted answer also isn't immune because its instructions also only mention the cell in isolation from its table view.
First, instantiate an offscreen instance of a table view cell, one
instance for each reuse identifier, that is used strictly for height
calculations.

Number of Cell prototypes exceeds tableview height

I have a tableview that has a large number of fairly tall dynamic cells. I've tried creating the prototypes for these but I've run out of height room in the view.
I can't seem to extend the height of the table view, (or the view it's in). I also can't create the tableview outside the viewController, give it a larger height, and just link to it.
Suggestions? I know I can create the cells programmatically or from a separate nib, but I'd really like to do it via storyboard.
thanks,
Just figured this out myself. Try this:
Double-click the table almost anywhere except where there's an existing control. You can also double-click on the outer edge of the table.
Note that the table view will show a highlighted section that aligns with the cell you've clicked. You've entered some sort of selection mode.
Now use the mouse to scroll up or down. The cells will shift up or down as if you were running the app.

Resources