【发布时间】:2018-04-26 12:51:10
【问题描述】:
我试过这个但没用Iterate over all the UITableCells given a section id 我只需要在单元格中迭代一个 for 循环并计算值并显示在另一个标签计算值或打印我不知道该怎么做。任何帮助都会很棒!我只有单元格的值我看到底部的单元格没有计算值。当我向上滚动时,我得到了单元格值,但顶部的单元格值无法查看或计算。
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
let news = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return news.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myTableView.dequeueReusableCell(withIdentifier: "mycellTVC") as! mycellTVC
cell.lbl.text = news[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
@IBOutlet weak var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
myTableView.delegate = self
myTableView.dataSource = self
}
}
**This is my cell file**
class mycellTVC: UITableViewCell{
@IBOutlet weak var lbl: UILabel!
@IBOutlet weak var calculated_value: UILabel!
}
【问题讨论】:
-
我在您的代码中看不到任何计算。你想达到什么目标?
-
你是要实现新闻的添加吗?
-
请检查我是否已编辑,当我的单元格位于下方且无法计算其值时会产生问题
-
你能澄清一下你的目标是什么吗?表格视图只有一个部分包含
news.count作为行数,并且您的代码到目前为止应该可以正常工作... -
为了更清楚,我想通过使用 for 循环为所有 10 行打印或另一个标签添加标签中的所有值。
标签: ios arrays swift uitableview