Tuna Yangir Tuna Yangir - 1 year ago 120
Swift Question

How can I make a menu like the picture shows?

How can I make a menu like the picture shows?

  1. When menu is clicked, a third menu needs to be opened

2. the menu click event and the same 3. menu open

@IBOutlet weak var tableView: UITableView!
var menu = [""]
var sections = [
altmenu:["Kişisel Bilgiler"],
section(UstMenuId:"Kişisel Bilgiler",
altmenu:["Öğrenim","Not Kartı"],

override func viewDidLoad() {

func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].altmenu.count
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (sections[indexPath.section].expanded) {
return 44
return 0
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 2
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = ExpandableHeaderView()
header.customInit(title: sections[section].UstMenuId, section: section, delegate: self)
return header
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell")!
cell.textLabel?.text = sections[indexPath.section].altmenu[indexPath.row]
return cell

func toggleSection(header: ExpandableHeaderView, section: Int) {
sections[section].expanded = !sections[section].expanded
for i in 0 ..< sections[section].altmenu.count{
tableView.reloadRows(at: [IndexPath(row: i, section: section)], with: .automatic)
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


This code came out like this:

My menu

Answer Source

i have already done a main and its submenu like collapsing tableview . If you need 2 submenu under a main i think you had better to use a library for this like TreeView .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download