Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // resultsController.swift
- // surveyApp
- //
- // Created by Sharoze Khan on 12/04/2019.
- // Copyright © 2019 Sharoze Khan. All rights reserved.
- //
- import UIKit
- import CoreData
- class resultsController: UIViewController, UITableViewDelegate, UITableViewDataSource {
- var answersData:[Data] = []
- override func viewDidLoad() {
- super.viewDidLoad()
- tableView.delegate = self
- tableView.dataSource = self
- //calling the fetch data function
- self.fetchData()
- self.tableView.reloadData()
- // Do any additional setup after loading the view.
- }
- @IBOutlet weak var tableView: UITableView!
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return answersData.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- //storing the core data into constants, allowing to call it in the string method.
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
- let id = answersData[indexPath.row]
- let dob = answersData[indexPath.row]
- let q1Experience = answersData[indexPath.row]
- let q2Activity = answersData[indexPath.row]
- let q3Usability = answersData[indexPath.row]
- let q4Future = answersData[indexPath.row]
- let latitude = answersData[indexPath.row]
- let longitude = answersData[indexPath.row]
- //string method
- cell.textLabel!.text = id.id! + " " + dob.dob! + q1Experience.q1Experience! + " " + q3Usability.q3Usability! + " " + q4Future.q4Future! + " " + latitude.latitude! + " " + longitude.longitude!
- return cell
- }
- //function to fetch data
- func fetchData(){
- let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
- do{
- answersData = try context.fetch(Data.fetchRequest())
- }
- catch{
- print(error)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement