UITableView different cell heights in different sections (no rows) - ios

I'm having a UITableViewController with two sections. Section 0 always contains 1 row with height 22px. I'm setting this with heightForRowAtIndexPath... Section 1 contains 0-n rows with height 44px. I'm also setting the height of these with heightForRowAtIndexPath.
The problem is that when I have no rows in section 1, all the "fill out cells" will have height 22px, like the cell in section 0, instead of 44px as I would like them to be.
Is it possible to set the height of these fill out cells to 44px (the cells that are empty and added automatically to fill out the table view) even if I only have the one row that is 22px?
Here is what I get (to the left) and what I want (to the right):

Instead of making your "status bar" its own section, you could make it a header view for section 1.

Try editing the UITableView attributes in the XIB - you can set a default row height so that if otherwise stated, all these "fill out" cells are defaulted to 44px height. You say that the 22px cell is there anyway so I think it should do as a solution to your problem.

I'm having the same problem here. Two sections, the first shows 3 cells with a smaller height and always with the same content and they should scroll with the table so they can't be a header. The rows below with a larger cell height are changing so sometimes there are none.
I adjusted the cell height of the tableView as well as for the prototype cells and assign the heightForRowAtIndexPath value properly, but this doesn't help. Somehow the tableView seems to repeat the cells from first section into the second one if there are no cells in the later.
Only solution so far seems to be the creation of an empty cell in the second section. That's just more complicated if you are using animated cells.

Related

set line spacing of static cells of tableview with storyboard

I want to know if there is a way to set the spacing between rows with static cells of tableview with storyboard.
I didn't find an attributor to do that:
I want to set the spacing between rows so it should like this:
You cannot do that. There are several options how you can deal with this.
Simulate the separator in the cell itself (e.g., see my question).
Use every other cell as a separator (so cell at row 0 will be normal cell, cell at row 1 will be a separator, cell at row 2 a normal cell, etc.).
Use section footers as a separators, in that case there will be section per every cell - numberOfSections will return number of all cells, numberOfRows will return 1. Then use footerForSection to provide appropriate "separator".
Nothing in attribute inspector to do that , you can do it like that
contentView
topView ----- height(static) ---- white background
spaceView ----- height (5) ---- gray background
Use UICollectionView
UITableView don't provide spacing between rows

Scrolling / static UITableView footer

I want to have a UITableViewCell with a behaviour mixed between a section footer and the table footer:
If the table is not filled (meaning there are not enough cells to fill the entire screen), the cell should stay at the bottom of the table, anchored to the screen edge, leaving blank space between itself and those above. (behaving like a table footer)
If the table is filled, the cell should start scrolling and always remain at the bottom of the table. (behaving like a section footer)
I'd like to avoid as much as possible weird tricks to achieve this, is there an elegant solution that allows me to do this?
Make your footer a separate view on top of the tableView with a constraint to the bottom of the tableView and take an outlet to this constraint. Override scrollViewDidScroll and get the bottom y coordinate of the last visible cell by using tableView.visible cells and calling CGRect.maxy on its frame (if there is no last cell your constraint constant is tableView.frame.size.height - footerView.frames.size.height). Take the difference of the tableView.frame.maxY and the last visible cell's maxY. If the cell is past the tableView.frame.maxY - footerView.frames.size.height then you set your constraint constant to 0, otherwise you set it to the difference.
This has the effect of pinning your footer view to the last visible cell, unless this would force the footer past the bottom of the table, in which case you just pin it to the bottom of the table instead. If there is no last cell you pin the footer to the top of the table.

In tableview i have 4 static cells. How do i make row height automatically calculated to fit the label inside and one manually

So i have four sections and one cell in each one of the sections in my static tableview. One of them is displaying a picture and for that one i manually calculate the ration and multiply it by the width and that way i get the correct height. I do that using the "heightForRowAtIndexPath".
I also have three other cells and each one has a label in it. The labels content is different each time since i'm segueing to it from a different cell so sometimes the cell should be big enough for 1 row of text and sometimes for more. How do i calculate/set that to happen automatically?
Also in my storyboard i have the constrains for the label set to be 8 point away from the right left and top, thats all the constrains that are on the label. I already tried setting the tableView.rowHeight to UITableViewAutomaticDimensions but that doesn't do anything. The rows just stay at the same height as they were set in the "heightForRowAtIndexPath" or the same as in the storyboard if that function is not implemented. Been trying to solve that for probably more then an hour now and still cant figure it out. Thanks for the help. Also i'm doing all of this in swift.
If you implement heightForRowAtIndexPath it will also override any value for the table view's rowHeight. So, in heightForRowAtIndexPath return UITableViewAutomaticDimension, and do the same in estimatedHeightForRowAtIndexPath too.
As long as your cell has a solid Auto Layout configuration, that's all it takes to make auto-sizing cells work.

Display one row in UICollectionView - Swift

I'm trying to figure out how to limit a UICollectionView to display a horizontal scrollable list in a single row.
Any Ideas?
I just used something that is working for me:
Set the Scroll direction to Horizontal.
Set the size of your Cells using sizeForItemAt indexPath method.
Set a constraint to your CollectionView making its height equal to (or a bit greater than) the Cell's height which you specified above.
The logic behind it:
When the height of CollectionView is equal to the height of it's items and it is set to horizontal scroll, then it can only show them in one row. I said "or a bit greater than cell's height" because if you set the height of your CollectionView twice bigger than cell's height then it can fit 2 rows of cells and it will show them in 2 rows instead of one.

Increasing height of tableview in storyboard to accommodate multiple prototype cells

I have multiple sections and multiple prototype cells in my tableviewcontroller. The prototype cells combined height exceeds the total height of the view. How can I accommodate all the cells in storyboard? Is there an option to increase the vertical height of the tableview?
I'm not sure if I understand your question. You can scroll the table view in the storyboard to see the rest of the cells.

Resources