swift - 如何在一个 UITableView 中显示 4 列数据,每个单元格使用 4 个不同的标签
问题描述
我目前正在开发一个应用程序,该应用程序允许用户将数据输入到表单中,并且数据将存储在本地的 coredata 中。管理员将在单元格中的表格视图中显示数据。有四种类型的数据必须记录到表格单元格中。我尝试在一个单元格中使用四个标签以允许将数据打印到单元格中。这是我现在的表格视图。
这是我现在的一些代码。
第一部分是关于代码如何提取数据并分配给四个标签。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return people.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let person = people[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Table_VC_Cell
cell.nameLabel.text = person.value(forKey: "name") as? String
cell.placeLabel.text = person.value(forKey: "place") as? String
cell.contactnoLabel.text = person.value(forKey: "contactno") as? String
cell.purposeLabel.text = person.value(forKey: "purposeofvisit") as? String
return cell
}
}
这部分是标签和代码的连接。
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var placeLabel: UILabel!
@IBOutlet weak var contactnoLabel: UILabel!
@IBOutlet weak var purposeLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
每当我在表单中输入数据后显示表格时,应用程序就会崩溃。Xcode 特别告诉我错误是由于这段代码造成的。我应该如何解决这个问题?
解决方案
推荐阅读
- mysql - 为什么我的连接不断中止?
- swiftui - SwiftUI 2.0 - 有没有办法确保加载器视图在加载大视图时首先可见?
- javascript - 通过 for 循环遍历对象的问题
- git - 忽略资源子文件夹最终会忽略所有资源文件夹
- java - WireMock 在使用 CustomHelper 时添加了意外字符
- spring-batch - 是否可以在 Spring Batch 中将列表项拆分为更小的块?
- reactjs - Framer 运动 - 如何进行简单的 CSS 颜色过渡
- amazon-dynamodb - DynamoDB 表的重用
- php - 为什么posts_per_page 在Wordpress 中不起作用?
- java - 我们如何在 selenium java 中使用 galen 框架生成页面转储