TableViews
Introduction to UITableViews and UITableViewDataSource. In the process we overviewed UITableViewCell, IndexPath and what it means to dequeue a cell.
Key classess and methods
- UITableView
- UITableViewDataSource - 2 required protocol methods:
numberOfRows
andcellForRow
- UITableViewCell
- IndexPath - key properties:
row
andsection
- dequeueReusableCell()
Topics Covered - Introduction
- UITableView
- cells can be static or dynamic
- prototype cell
- reuse identifier e.g "countryCell"
- dataSource object (WE NEED TO SET THE DATASOURCE OBJECT e.g tableView.dataSource = self), configured in viewDidLoad()
- UITableViewDataSource - 2 required methods
- first required method is
numberOfRows()
- second required methods is
cellForRow()
dequeueCell
- recycles a cell if in memory, if not it creates a new cell- [indexPath.row] - gets object for row at current indexPath
- UIBarButtonItem - button in navigation bar
- extension {...} - used to extend a class, in our case to conform to the UITableViewDataSource
Topics Covered - Table View Sections
- UITabBarController
- UITabItem
viewControllers relationship segue
connects a tab bar controller to a view controllerArray(repeating: , count: )
numberOfSections()
- UITableViewDataSource method, returns number of sections in the table viewtitleForHeaderInSection()
- UITableViewDataSource method, returns a String for each section headerprepare(for segue: )
- here you set the data to be passed to the destination view controller- segue.destination
- segue.source
- tableView.indexPathForSelectedRow
- [indexPath.section][indexPath.row] - gets thte section and the row at the current indexPath