Add separator in grouped tableview cell - iphone

I have table cell with 1 textfield & 1 uiswitch placed in single cell. I have table cell of height 100. How can I add separator to this cell so that there is distinction between textfield & uiswitch?

Assuming that you are adding subviews to your cell, you would need to create a custom view with a switch and a separator (a graphic or something else) to add to your cell as a subview.
Question: if you are adding a switch and a textfield, shouldn't they be in two separate cells anyway? That way you would get a natural horizontal divider.

Related

Square table cell in a table view

Instead of having table cells that takes the entire width of the screen, I would like to have square table cell, so that I can have maybe 3 or 4 table cells per line. The table cell would also change its size on the vertical dimension.
Is it possible ?
Thanks !
You should use UICollectionView instead of UITableView.

Automatic Cell Height Without Custom Cell?

I would like the Subtitle-style cells in my iOS 8 table view to resize automatically in height to allow subtitle content of any number of lines. And, I would like to accomplish this without using custom cells, if possible. That is, I would like to use the "canned" prototype cells that are available when dragging a new TableViewController to the story board.
I have found that this is easy to do with Basic-style cells: that is, prototype cells with Style set to "Basic" so that there is just one label in the cell -- "Title", by default. This is the label that is accessible by cell.textLabel!.text in code. If I set that textLabel's number of lines to 0, and add the two lines below to viewDidLoad(), then the cell heights resize automatically:
tableView.estimatedRowHeight = 144.0
tableView.rowHeight = UITableViewAutomaticDimension
All without having to define a custom cell or muck around with auto-layout or constraints. (In fact, I find it's not possible to add constraints to a canned prototype cell.)
But if I change the cell Style to "Subtitle," so that there are two labels in the cell -- textLabel and detailTextLabel in code -- then the cells do not automatically resize in height, even after setting both (or either) line numbers to 0 and playing around with different estimatedRowHeight values.
Am I missing something, or is it not possible to automatically resize cell height without a custom cell?
Thank you!
or is it not possible to automatically resize cell height without a custom cell?
Yes, it is not possible. And the reason is the reason that you gave. The automatic-resizing-cell-height feature depends upon internal constraints. But, as you have rightly said:
it's not possible to add constraints to a canned prototype cell.
However, note that you can accomplish what you want without supplying a cell subclass (though personally I like supplying one). You can just design your cell, constraints and all, right there in the prototype cell — the Custom prototype cell.

xcode ignores table view cell height selection and uses table view row height selection

I'm creating a UItableView with two different dynamic custom cells and want both cells to have different default height. I can't seem to do this since the cells always take the height specified in the table view row height option instead of the table view cell height option.

Cell Separator Style

How can we set Separator style at cell level. i.e. each cell will be having different separator style?
I don't think you can set the cell separator style per cell. You might try setting the table view separator to UITableViewCellSeparatorStyleNone and then draw a custom "separator" yourself when you render out each cell.
Edit: How to do it depends a lot on your current code, what type of table, whether you are using a custom table cell, what exactly you mean by "different separator style", etc.
I have not tried this, but one option I can think of off the top of my head would be to use the UITableViewCell.backgroundView property. You could add a subview with a different color that is only a few pixels high along the bottom or you could create a UIImageView that fills the backgroundView and set the image to achieve the "different" separator.

How do I resize a cell in a tableview with grouped cells

I am using a grouped tableview and need to resize 1 cell where the enclosed cell.detailTextLabel has exceeded the size of the cell (i.e. about 3 lines worth).
Is there any easy way for the cell to auto-size itself to it's contents or otherwise, how do I change the size of that particular cell?
The UITableViewDelegate has a method called tableView:heightForRowAtIndexPath:. Just have it return the desired height for each row.