Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. class TableViewController: UITableViewController {
  2.  
  3. var bDays = [
  4. "Коты": ["Мурка", "Пушистик"],
  5. "Собаки": ["Шарик", "Песик"],
  6. "Мыши": ["Маус", "Крыс"]]
  7.  
  8.  
  9. struct Objects { //Вспомогательная структура
  10. var sectionName : String!
  11. var sectionObjects : [String]!
  12. }
  13.  
  14. var objectArray = [Objects]() // Источник данных
  15.  
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18.  
  19. for (key, value) in bDays {
  20. objectArray.append(Objects(sectionName: key, sectionObjects: value))
  21. }
  22. }
  23.  
  24.  
  25. // MARK: - Table view data source
  26.  
  27.  
  28. // Получим количество секций в таблице
  29. override func numberOfSections(in tableView: UITableView) -> Int {
  30. return objectArray.count
  31. }
  32.  
  33.  
  34. // Получим количество строк для конкретной секции
  35. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  36. return objectArray[section].sectionObjects.count
  37. }
  38.  
  39.  
  40. // Получим заголовок для секции
  41. override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  42. return objectArray[section].sectionName
  43. }
  44.  
  45.  
  46. // Получим данные для использования в ячейке
  47. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  48. let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
  49.  
  50. // Configure the cell...
  51. cell.textLabel?.text = objectArray[indexPath.section].sectionObjects[indexPath.row]
  52. return cell
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement