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
Related
Presently my output is this but I need the layout to be little more organized.
I want the frame.origin.y for 1 and 2 cells to be the same as cell 0.
I have made section insets and min spacing all 0.
To brief it, I want the 1,2,3,4 cells to be adjusted in the first row.
Is there any way I can achieve this?
On Dynamically increasing height of one collectionview cell gap is seen in other cell. How to get rid of the unwanted gap.
Please help
1. Collection view before expanding cell
2. Collection view after dynamically expanding height of the cell on button click -- GAP seen
I am using AutoLayout to layout the cells of my tableView. When the content of some elements I have in the cell is empty, I would like to hide the cell.
My issue is that if I flag the cell to be hidden with:
cell.hidden = YES;
then the "space" used by the cell (whose height is computed in heightForRowAtIndexPath) is still there but grayed out. In effect, the cell is hidden but it's still part of the "flow".
If I try to set the height to zero on the cell I want to hide in the heightForRowAtIndexPath, then I get an exception being raised because auto layout cannot satisfy all the constraints.
Is there a simple way to hide a cell and remove it from the "flow" of the display or do I have to update my constraints on the cell to allow for a height of 0 to achieve that?
Thanks,
Nicolas
You need to update your data model to not include the cell, so that it isn't returned in cellForRowAtIndexPath:.
Alternatively, you could disable auto layout on the cell when you're setting the height to 0:
[cell removeConstraints:cell.constraints]
I have 3 labels in a UITableViewCell and have the labels set so they will wordwrap. If they word wrap the text goes into the next cell. How do I get AutoLayout to expand the cell based on the content without having to write code in the heightForRowAtIndex method? Isn't there a constraint I can use to automatically adjust the cell based on the contentView?
The cell looks fine if the text doesn't wrap in the label. Once it wraps that is when the problem occurs and I would like to have the cell resize to fit the content and have the same spacing between the bottom label and the bottom as there is between the top and top label.
Unfortunately no, you can't do this. A table view calculates its own total height first and has a fixed idea of the size of each cell as they load, it won't determine it's height from the outside in and it won't let layout constraints change the height of a cell.
If you think about how tables work, with cell reuse, then you couldn't really size the table from its cells without loading in every cell and adding it to the scrollview, and performing a layout pass on the whole thing. That would probably lead to quite poor performance.
You could experiment with populating a "free" cell (i.e a cell you've just instantiated, not added to a table) and laying it out for each row in your datasource when calculating heightForRow.
As you are loading the individual cells, after you fill the labels, but before you load the instance of the cell, check the label height.
Something like:
cell.frame.size.height
If the height is large enough that you know the label has wrapped to two lines, then increase the height of the cell you are about to load.
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.