Created
July 28, 2014 16:44
-
-
Save hartbit/4f5c85cd3d746f1e0621 to your computer and use it in GitHub Desktop.
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
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