Expandable UITableView Without Section

Come lets play with UITableView

Tony Wilson jesuraj
2 min readJan 20, 2021

lets Expandable and play with tableview cell without section and with stackView

Im skipping tableView setting steps and into the cell content view :)

simple just drag a stackView and put two view inside it (TopView and bottom view)

contentview
|
-----StackView
|
------ TopView
|
------ BottomView

Don’t forget to select the Axis -vertical and Distribution -in any Fill in StackView

then while creating outlet just hide the bottomView like i did

@IBOutlet weak var bottomView: UIView! {
didSet {
bottomView.isHidden = true
}
}

That’s all guys just put the below code at didSelectRowAt

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? ExpandableTableViewCell {
UIView.animate(withDuration: 0.9) { cell.bottomView.isHidden = !cell.bottomView.isHidden if cell.topLabel.text == "-" { cell.topLabel.text = "+" } else { cell.topLabel.text = "-"
}
}}

Registered let cell to use the outlets in the TableViewCell

  • you know what Im doing in cell.bottomView.isHidden = !cell.bottomView.isHidden
  • you can handle the label texts like i did above

Look easy like eating cup cakes

Here our stackView will take care the work.

--

--

Tony Wilson jesuraj
Tony Wilson jesuraj

No responses yet