【问题标题】:tableView shows up after rotation旋转后出现tableView
【发布时间】:2016-04-29 13:08:15
【问题描述】:

当我运行它时,我第一次打开历史选项卡时,tableView 上什么也没有显示。只有在我旋转屏幕之后,事情才会出现,但它们仍然很有趣。两个标签只有在旋转屏幕后才会出现。有时并不是所有的历史都被展示出来。我读到我缺少一些初始化程序,但是一旦更改内容,我就会不断收到错误...任何帮助将不胜感激

//
    //  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()

        }

    }

【问题讨论】:

    标签: ios swift cocoa tableview reload


    【解决方案1】:

    很确定你需要在 let 和 if 中间添加你的声明。这将允许您访问 API 中的必要密码。然后,端点将允许您对源代码的请求,而不会将其视为 SSL 错误。

    【讨论】:

    • 什么?很抱歉不明白你的意思
    • 我看到您已经获得了布尔值的声明和覆盖函数。即使初始化命令设置正确,这有时也会导致问题。这就是为什么我们需要添加故障保护。当我运行 Linux ngin 以及将 Tomcat 7 部署到 Oracle 数据库时,我已经多次这样做了。这也可以限制将来任何丢失的数据包,以防 TCP 在第一次尝试后决定退出。
    • 那我该如何解决呢?抱歉,我真的不明白你在指导我什么;(
    【解决方案2】:

    一个可疑的事情是您使用 indexPath.item 而不是 indexPath.row 来索引 newHistory[]。当 indexPath 应用于 UITableView 时,我不完全确定 .item 是否正确设置。

    【讨论】:

    • 同样的结果 :( 还有其他想法吗?
    【解决方案3】:

    creating custom tableview cells in swift

    这就是问题的解决方案……

    取消选中尺寸等级复选框

    即使重新打开它仍然可以工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 1970-01-01
      • 2022-06-16
      • 2011-02-08
      • 2014-07-06
      相关资源
      最近更新 更多