Skip to content

Instantly share code, notes, and snippets.

@kvendrik
Created March 3, 2016 18:54
Show Gist options
  • Select an option

  • Save kvendrik/f78dfbb61711d6927f0c to your computer and use it in GitHub Desktop.

Select an option

Save kvendrik/f78dfbb61711d6927f0c to your computer and use it in GitHub Desktop.
Simple List Class in Swift
//put UITableView in a UIView and point the data source and delegate of the UITableView to the UIView
class ListTableView: UIView, UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: nil)
cell.textLabel?.text = "Item \(indexPath.row + 1)"
cell.detailTextLabel?.text = "Subtitle \(indexPath.row + 1)"
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment