首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我的单元没有出现在我的tableView中

我的单元没有出现在我的tableView中
EN

Stack Overflow用户
提问于 2017-06-20 09:53:57
回答 2查看 48关注 0票数 0

我的应用程序在几分钟前就像预期的那样工作了,但我按了很多“撤销”键来查看我是如何写出我已经删除的内容的,然后我又按了“重做”键,直到我所有的新代码都回来了,但我的tableView中的自定义单元格没有出现在应用程序中。我看到的只是一个空的tableView。

代码语言:javascript
运行
复制
import UIKit

class MyTableViewCell: UITableViewCell {

    @IBOutlet weak var labelHole: UILabel!

    @IBOutlet weak var labelShots: UILabel!
}

class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var holesTableView: UITableView!


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return mainShotsEachHole.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = holesTableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyTableViewCell

        cell.labelHole?.text = "Hole \(mainCurrentHoleNumber)"

        cell.labelShots?.text = "\(mainShotsEachHole[indexPath.row])"

        return cell
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        holesTableView.register(MyTableViewCell.self, forCellReuseIdentifier: "cell")

        holesTableView.delegate = self
        holesTableView.dataSource = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

谢谢你可能得到的帮助。我已经试着解决这个问题一个小时了,但我似乎不能让它工作。

*编辑-为ViewController.swift添加代码,提供一些数据。

代码语言:javascript
运行
复制
import UIKit

var mainCounterValue = 0
var mainCurrentHoleNumber = 1
var mainShotsEachHole = [Int]()


class ViewController: UIViewController {

    @IBAction func unwindToViewController (segue: UIStoryboardSegue){

    }

    @IBOutlet weak var mainCounter: UILabel!

    @IBOutlet weak var mainHoleNumber: UILabel!

    @IBAction func mainButtonNextHole(_ sender: Any) {
        mainShotsEachHole.append(mainCounterValue)
        mainCurrentHoleNumber += 1
        mainHoleNumber.text = "Hole \(mainCurrentHoleNumber)"
        mainCounterValue = 0
        mainCounter.text = "\(mainCounterValue)"
    }


    @IBAction func mainButtonMinus(_ sender: Any) {
        if (mainCounterValue > 0) {
            mainCounterValue -= 1
        } else {
            mainCounterValue = 0
        }
        mainCounter.text = "\(mainCounterValue)"
    }

    @IBAction func mainButtonPlus(_ sender: Any) {
        mainCounterValue += 1
        mainCounter.text = "\(mainCounterValue)"
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
EN

回答 2

Stack Overflow用户

发布于 2017-06-20 10:09:04

您需要调用holesTableView.reloadData()来填充您的表

票数 0
EN

Stack Overflow用户

发布于 2017-06-20 13:21:06

holesTableView.register(UINib(nibName:"nibName",bundle: nil),forCellReuseIdentifier:"cell")

尝试上面的代码,希望能对你有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44642574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档