UITableView
Reuse
Why? Memory. Allows you to have a table with thousands of cells without having thousands of cell objects in memory
UITableViewCell
Styles
(IB -> enum)
- Basic (.default) - no detail
- Right Detail (.value1) - detail is gray and on the right
- Left Detail (.value2) - detail is on the right and label is blue, no image space
- Subtitle (.subtitle) - detail is below and smaller text
Concepts
- contentView - the main contents - will be resized in editing mode
- accessory view - the thing to the right
Mutation
Add
tableView.insertRows(at: [indexPath], with: .automatic)
Move
override func tableView(_ tableView: UITableView,
moveRowAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
// change in underlying data
}
Delete
override func tableView(_ tableView: UITableView,
commit editingStyle: UITableViewCell.EditingStyle,
forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// change in underlying data
}
}
Slapdash