0

When I run this, the first time I open History tab, nothing shows up on the tableView. Only after I rotate the screen things show up but they are still being funny.Both labels show up only after rotating the screen. Not all the history is being shown as well sometimes. I read that I am missing some initializer but I keep getting errors once change things... Any help will be appreciated

//
    //  SecondViewController.swift
    //
    //  Created by Artiom Sobol on 1/3/16.
    //  Copyright © 2016 Artiom Sobol. All rights reserved.
    //

    import UIKit

    class History: UIViewController, UITableViewDataSource, UITableViewDelegate
    {
        // test variable
        var test: MyHistory!
        // array to store unarchived history
        var newHistory = [MyHistory]()

        //outlet for tableview

        @IBOutlet var tableView: UITableView!


        override func viewDidLoad()
        {

            //change the background
            self.view.backgroundColor = UIColor(patternImage: UIImage(named: "newBackground.jpg")!)

            super.viewDidLoad()
            tableView.delegate = self
            tableView.dataSource = self

            //self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "historyCell")

            self.tableView.reloadData()
            //unarchive any new data
            let defaults = NSUserDefaults.standardUserDefaults()
            if let savedPeople = defaults.objectForKey("MyHistory") as? NSData {
                newHistory = NSKeyedUnarchiver.unarchiveObjectWithData(savedPeople) as! [MyHistory]
            }

        }

        func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int
        {
            if (newHistory.count < 1)
            {
                return 1
            }
            else
            {
                return self.newHistory.count
            }
        }

        func numberOfSectionsInTableView(tableView: UITableView) -> Int
        {
            return 1
        }

        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
        {

            let cell = tableView.dequeueReusableCellWithIdentifier("historyCell", forIndexPath: indexPath) as! historyCell
            let person = newHistory[indexPath.item]
            let defaults2 = NSUserDefaults.standardUserDefaults()

            print("This is count", newHistory.count)

            if let savedPeople = defaults2.objectForKey("MyHistory") as? NSData {
                newHistory = NSKeyedUnarchiver.unarchiveObjectWithData(savedPeople) as! [MyHistory]
            }



           // cell.durationLabel.text = String(person.durationNumber)
            let (hour,minutes,seconds) = secondsToHoursMinutesSeconds(person.durationNumber)

            if(seconds < 10 && minutes < 10)
            {
                cell.durationLabel.text = "0\(hour):0\(minutes):0\(seconds)"
            }
            else if(seconds > 9 && minutes < 10)
            {
                cell.durationLabel.text = "0\(hour):0\(minutes):\(seconds)"
            }
            else if(seconds > 9 && minutes > 9)
            {
                cell.durationLabel.text = "0\(hour):\(minutes):\(seconds)"
            }
            else if(seconds < 10 && minutes > 9)
            {
                cell.durationLabel.text = "0\(hour):\(minutes):0\(seconds)"
            }


            cell.kicksLabel.text = String(person.kicksNumber)

            return cell
        }


        func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int)
        {
            return (seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60)
        }

        override func viewWillAppear(animated: Bool)
        {
            super.viewWillAppear(animated)
            self.tableView.reloadData()

        }

    }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

3 Answers3

0

Pretty sure you need to add your declare right in the middle of let and if. This will allow you to reach the necessary cyphers that are in place within the API. The endpoint will then allow your request to the source code and not view it as an SSL error.

  • 1
    what? I'm sorry no idea what you mean – Triscuit Delicious Jan 22 '16 at 20:57
  • I see you've already got your declares and the override function for Boolean. This sometimes causes issues, even if the initializing commands are set correctly. This is why we need to add in the failsafe. I've done this numerous times back when I was running a Linux ngin and when I was deploying Tomcat 7 to an Oracle database. This can also limit any lost packets in future just in case TCP decides to conk out after its first attempt. – Caratacus012 Jan 22 '16 at 21:43
  • So how would i Fix it ? sorry I don't really understand what you guiding me through ;( – Triscuit Delicious Jan 23 '16 at 03:09
0

One suspicious thing is that you're indexing newHistory[] using indexPath.item instead of indexPath.row. I'm not entirely certain that .item is properly set when the indexPath applies to a UITableView.

Alain T.
  • 40,517
  • 4
  • 31
  • 51
0

creating custom tableview cells in swift

this is the solution to the problem...

UNCHECK THE Size Classes checkbox

Even after turning it back on it still works

Community
  • 1
  • 1