Skip to content

Instantly share code, notes, and snippets.

@hartbit
Created July 28, 2014 16:44
Show Gist options
  • Save hartbit/4f5c85cd3d746f1e0621 to your computer and use it in GitHub Desktop.
Save hartbit/4f5c85cd3d746f1e0621 to your computer and use it in GitHub Desktop.
protocol TableControllerDelegate {
typealias ItemType
func tableViewCellForItem(item: ItemType, atIndexPath indexPath: NSIndexPath) -> UITableViewCell
}
class TableController<T> : NSObject, UITableViewDataSource, UITableViewDelegate {
var items: [T]?
var delegate: TableControllerDelegate?
//MARK: UITableViewDataSource & UITableViewDelegate Methods
public func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return 1
}
public func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return self.items ? items!.count : 0
}
public func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
return self.delegate?.tableViewCellForItem(self.items![indexPath.row], atIndexPath: indexPath)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment