Expandable and Collapsible Sections UITableView (Ep 3)
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking how to make UITableView sections expand and collapse, since it walks through a working implementation step by step.
Recommended by 3 people across 3 different months, 2018 to 2024.
What it is
A 20-minute iOS tutorial from the Lets Build That App channel showing how to build expandable and collapsible sections in a UITableView in Swift, similar to an accordion. It uses a simple approach built around an isExpanded flag per section and tappable header views, and the presenter notes there is room to improve it.
What people said
Recommends Shubham Bakshi · 2018-10 · Stack Overflow · on “Expanding tableview sections on clicking each section”
This kind of feature requires a bit more code and I cannot write the whole code here but I can explain you the concepts that will be used to achieve this and will attach a few good tutorials which I used to ultimately create a feature like this First you need to create a custom HeaderView for your sections Next you need a UITapGestureRecognizer on your section and need to write your login inside the function provided in action part of UITapGestureRecognizer 's constructor You need to create a separate Protocol inside your HeaderView file and your ViewController that contains your TableView will adopt to that protocol and will handle whether to expand or collapse your rows Also, you will need
Recommends Sreekanth M · 2020-04 · Stack Overflow · on “headers are removed when expanding a section in a UITableView”
Yes its possible with headers, Add tag and UITapGestureRecogniser for all header views Add isExpanded boolean key to settings data structure here you go, write an action method for gesture @objc func handleTapGesture(_ sender:UIGestureRecogniser) { let gesture = UIGestureRecognizer.init() guard let section = gesture.view?.tag else { return } let indexPaths = [IndexPath]() for row in settings[section].options.indices { let indexpath = IndexPath.init(row: row, section: section) } // revising the value.... let isExpanded = settings[section].isExpanded settings[section].isExpanded = !isExpanded if isExpanded { tableView.deleteRows(at: indexPaths, with: .fade) } else { tableView.insertRows(at: in
Recommends Akos Farkas · 2022-01 · Stack Overflow · on “Duplicating UIViews in StackView when scrolling TableView Swift”
If I understand correctly, you would like to create an expandable TableView? If yes you can do it a lot of different ways, but you have to change your approach totally. Please refer LBTA approach: LBTA video [this video] My favourite the Struct approach, where you create a struct and you can save the complication with the 2D array: Struct stackoverflow link [LINK]
Cites Adrian · 2018-07 · Stack Overflow · on “Add UIView Above All Section in UITableView Swift”
@ZainAnjum Expanding upon @gadu's proposed solution, what you could do is create an IBDesignable UIView and for each button, in `viewForHeaderInSection`, assign a tag to the button's from `viewForHeaderInSection's` `section` (it'd look something like `plusButton.tag = section`. Then, you could tie a target to it (`plusButton.addTarget ` and create a method to do whatever you want to do with the button. You'd just pull the tag off the sender to know what section it came from. [this video]
Cites Tian-Xiang Leong · 2019-07 · Stack Overflow · on “Data structure for Expandible and Collapsible Sections in UITableview”
I have a UITableViewController which shows a list of transactions sorted by date. This is for a personal finance / banking-style app. What I want to achieve: The section headers (which show the date) should expand/collapse when tapped. I'm using Realm database to store my transaction data. I'm a beginner programmer and I've tried to google a solution but I'm stuck trying to create data structure to track whether a section is opened or closed. I've tried following this ( [this video] ) but I get stuck at 12:00. Realm model: class Transaction: Object { @objc dynamic var amount: Float = 0 @objc dynamic var toFrom: String = "" @objc dynamic var category : String = "" @objc dynamic var date: Date? = n
Cites mystic cola · 2024-06 · Stack Overflow · on “Swift Converting Codable Variable to String Array”
I'm following this tutorial on creating a collapsible TableView: [this video] He's loading a String array of names into the tableview like so: struct ExpandableNames { var isExpanded: Bool let names: [String] } var twoDimensionalArray = [ ExpandableNames(isExpanded: true, names: ["Amy", "Bill", "Zack", "Steve", "Jack", "Jill", "Mary"]), ExpandableNames(isExpanded: true, names: ["Carl", "Chris", "Christina", "Cameron"]), ExpandableNames(isExpanded: true, names: ["David", "Dan"]), ExpandableNames(isExpanded: true, names: ["Patrick", "Patty"]), ] I would instead like to create the String array of names from my Codable User model's "name" variable: struct User: Codable { //var id: Int var user_id: In