Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. //
  2. // resultsController.swift
  3. // surveyApp
  4. //
  5. // Created by Sharoze Khan on 12/04/2019.
  6. // Copyright © 2019 Sharoze Khan. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import CoreData
  11.  
  12. class resultsController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  13.  
  14. var answersData:[Data] = []
  15.  
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18.  
  19. tableView.delegate = self
  20. tableView.dataSource = self
  21.  
  22.  
  23. //calling the fetch data function
  24. self.fetchData()
  25. self.tableView.reloadData()
  26.  
  27. // Do any additional setup after loading the view.
  28. }
  29.  
  30. @IBOutlet weak var tableView: UITableView!
  31.  
  32.  
  33. func numberOfSections(in tableView: UITableView) -> Int {
  34. return 1
  35. }
  36.  
  37. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  38. return answersData.count
  39. }
  40.  
  41. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  42.  
  43.  
  44.  
  45. //storing the core data into constants, allowing to call it in the string method.
  46. let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
  47. let id = answersData[indexPath.row]
  48. let dob = answersData[indexPath.row]
  49. let q1Experience = answersData[indexPath.row]
  50. let q2Activity = answersData[indexPath.row]
  51. let q3Usability = answersData[indexPath.row]
  52. let q4Future = answersData[indexPath.row]
  53. let latitude = answersData[indexPath.row]
  54. let longitude = answersData[indexPath.row]
  55.  
  56. //string method
  57. cell.textLabel!.text = id.id! + " " + dob.dob! + q1Experience.q1Experience! + " " + q3Usability.q3Usability! + " " + q4Future.q4Future! + " " + latitude.latitude! + " " + longitude.longitude!
  58.  
  59. return cell
  60. }
  61.  
  62.  
  63.  
  64. //function to fetch data
  65. func fetchData(){
  66. let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
  67.  
  68. do{
  69. answersData = try context.fetch(Data.fetchRequest())
  70. }
  71. catch{
  72. print(error)
  73. }
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement