gpt4 book ai didi

swift - 我的单元格没有出现在我的 tableView 中

转载 作者:行者123 更新时间:2023-11-30 12:22:20 24 4
gpt4 key购买 nike

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

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 添加代码。

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.
}


}

最佳答案

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

关于swift - 我的单元格没有出现在我的 tableView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44642574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com