Skip to content

Instantly share code, notes, and snippets.

@tsraveling
Created April 18, 2017 23:57
Show Gist options
  • Save tsraveling/4294e8bfacff2fd2a9373171aa033347 to your computer and use it in GitHub Desktop.
Save tsraveling/4294e8bfacff2fd2a9373171aa033347 to your computer and use it in GitHub Desktop.
Menu UITableView delegate
// MARK: - Menu UITableView Delegate and Datasource -
enum MenuItem : String {
case <#T##key#> = "<#T##Value#>"
static var items = [ <#T##all values#>]
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MenuItem.items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = MenuItem.items[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "<#T##cell#>", for: indexPath) as! <#T##cell class#>
// Configure the cell...
cell.<#T##text label#>.text = item.rawValue
return cell
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let item = MenuItem.items[indexPath.row]
switch item {
case <#T##value#>:
break
default:
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment