Created
June 11, 2015 23:41
-
-
Save codebeaulieu/036fff790d50ab6e5b5b to your computer and use it in GitHub Desktop.
SideBarTableViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
protocol SideBarTableViewControllerDelegate { | |
func sideBarControlDidSelectRow(indexPath: NSIndexPath) | |
} | |
class SideBarTableViewController: UITableViewController { | |
var delegate : SideBarTableViewControllerDelegate? | |
var tableData : [String] = [] | |
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return 1 | |
} | |
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return tableData.count | |
} | |
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
var cell = tableView.dequeueReusableCellWithIdentifier("cell") | |
if cell == nil { | |
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell") | |
// configure | |
cell?.backgroundColor = UIColor.clearColor() | |
cell?.textLabel?.textColor = UIColor.darkTextColor() | |
let selectedView : UIView = UIView(frame: CGRect(x: 0, y: 0, width: cell!.frame.size.width, height: cell!.frame.size.width)) | |
selectedView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3) | |
cell!.selectedBackgroundView = selectedView | |
} | |
cell!.textLabel!.text = tableData[indexPath.row] | |
return cell! | |
} | |
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { | |
return 45.0 | |
} | |
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
delegate?.sideBarControlDidSelectRow(indexPath) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment