gpt4 book ai didi

swift - 无法在表格中毫无问题地显示多个文本标签

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

我在 swift 上使用以下代码来尝试让它显示多个文本标签,但由于某种原因,它在表格上只显示操作系统标签。

这可能是非常明显的事情,我只是愚蠢/盲目,但我一生都找不到它。谢谢。

func tableView(tableView: UITableView, 
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
reuseIdentifier: "Default")

cell.textLabel?.text = servInfo.servers[indexPath.row].name
cell.textLabel?.numberOfLines = 0
cell.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.textLabel?.text = "Username: " + servInfo.servers[indexPath.row].username
cell.textLabel?.text = "Password: " + servInfo.servers[indexPath.row].password
cell.textLabel?.text = "IPv4 Address" + servInfo.servers[indexPath.row].ipv4
cell.textLabel?.text = "IPv6 Address" + servInfo.servers[indexPath.row].ipv6
cell.textLabel?.text = "Protocol:" + servInfo.servers[indexPath.row].pcal
cell.textLabel?.text = "Operating System: " + servInfo.servers[indexPath.row].os
cell.detailTextLabel?.text = servInfo.servers[indexPath.row].addi

return cell
}

最佳答案

您没有连接字符串。您正在删除 cell.textLabel 的内容并在每一行中写入新文本。

使用字符串连接。

使用这个:

cell.textLabel.text += ("blabla"+ "\n");

cell.textLabel.text += ("blabla"+ "\n");

或使用这个:

cell.textLabel.text = cell.textLabel.text + ("blabla"+ "\n");

cell.textLabel.text = cell.textLabel.text + ("blabla"+ "\n");

而不是这个:

cell.textLabel.text = "blabla";

cell.textLabel.text = "blabla";

关于swift - 无法在表格中毫无问题地显示多个文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31369189/

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