我有一个函数,我想要一个大文本标签和两个较小的文本标签。 该函数从数据库中获取数据,并将它们重复放入我的 3 个文本标签中。 但是,只有我的默认文本标签可见,两个详细文本标签都不显示。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Retrieve cell
let cellIdentifier: String = "BasicCell"
let myCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
// Get the location to be shown
let item: Parsexml = feedItems[indexPath.row] as! Parsexml
// Get references to labels of cell
print(item)
myCell.textLabel!.text = item.name! + " | " + item.address! + " " + item.nr!
myCell.detailTextLabel?.text = "City: " + item.city!
myCell.detailTextLabel?.text = "category: " + item.category!
//Label styling
myCell.textLabel?.textColor = UIColor(white: 1, alpha: 1)
myCell.textLabel?.font = UIFont(name: "HelveticaNeue-Bold", size: 12)
return myCell
}
如何让我的详细文本标签在 swift 3 中显示?
最佳答案
这意味着您有一个包含 3 个 UILable 的自定义单元格? 如果是这样的话,这一行应该是这样的
let myCell: YouCustomCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
然后你就可以使用
myCell.1stLable.text = item.name! + " | " + item.address! + " " + item.nr!
myCell.2ndLable.text = "City: " + item.city!
myCell.3rdLable.text = "category: " + item.category!
您必须在 Storyboard中设置单元格标识符。
关于ios - 详细文本标签不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40202453/