Tuna Yangir Tuna Yangir - 1 year ago 113
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



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

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


override func viewDidLoad() {
super.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
}else{
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
tableView.beginUpdates()
for i in 0 ..< sections[section].altmenu.count{
tableView.reloadRows(at: [IndexPath(row: i, section: section)], with: .automatic)
}
tableView.endUpdates()
}
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