0

I want to create a table view something look like this image below...

table view cell

Not all cells has extra values but all cells have title description. When clicking "Show Details" button, cell will expand with animation. I have following questions.

  1. Is it necessary to design 2 cells (one cell for title and description and another for title, description and extra values)
  2. How to expand cells when clicking "Show Details" button. Some cells will have description only and some cells will have both description and extra values.
  3. Which will be more efficient ? auto resizing or auto layout in this case.

Any suggestion will be helpful.

WAHID MARUF
  • 51
  • 1
  • 8
  • Possible duplicate of [Expand UILabel inside UITableView with "more" button like Instagram](https://stackoverflow.com/questions/43096231/expand-uilabel-inside-uitableview-with-more-button-like-instagram) – DonMag Nov 26 '17 at 15:35

1 Answers1

0

Here are the answers:

  1. No, it's not. But I would say more precise answer if you could please show the design of the cell that will not have the button "show details". But basically, I would say that the rule is "if the top part is the same then you can use the same design for both cells". Since what you will do is just hide the bottom part of the cell. It will be hidden due to the smaller height of the cell. BUT: taking consideration that you want to make it lite you may don't want to have a redundant bottom part of the cell which is hidden from doing nothing. So ideally is to have 2 separate cells but answering your question it is not necessary.

  2. Here you have 2 questions: how to check the click + how to expand. I'll explain 1 by 1.

2.1. How to check the click: create a delegate in the cell class that will tell your view controller that the button "show details" was tapped and then expand the cell in the view controller.

2.2. Simply use heightForCellAtIndexPath to regulate the height of the cell. If it's expanded then make it higher if not make it shorter. But main point here is that when the delegate method gets called you need to call tableView.reloadRows(at:) where you need to reload the cell with animation and it will expand the cell with a nice animation. Btw I prefer using .fade animation.

  1. I think I answered this one above but please let me know if it's not clear yet.

Hope it helps.

Tung Fam
  • 7,899
  • 4
  • 56
  • 63
  • Should I use automatic height calculations for this purpose or calculate of the cell height of my own ? – WAHID MARUF Nov 26 '17 at 17:22
  • @WAHIDMARUF it’d be preferable to use automatic height, and let the cell recalculate it’s height based on auto layout constraints. As well as you can use the table views beginUpdates and endUpdates method to animate the cells height change just take a look at the documentation for that :) – Justin Guedes Nov 26 '17 at 19:08
  • one small question, can you please tell me should I use Label or text View for "extra values with value 1, value 2, value 3 " part ? I have to use attributes for this. But what will be more efficient for this ? – WAHID MARUF Nov 27 '17 at 05:41
  • As I understand the quantity of lines of values varies right? Then I would use a stack view with UIView that contains 2 labels (value 1 and the price) – Tung Fam Nov 27 '17 at 07:26