你好,我的代码中有一个非常奇怪的问题,我不知道这里到底发生了什么。
我在我的 View Controller 中设置了 label
并且当我像这样设置值时
cell.totalTripsLabel.text = "55"
它有效。
但是如果我尝试从字典中设置值,
cell.totalTripsLabel.text = self.dict["totalTrips"]! as? String
它根本不起作用,ViewController 上没有显示任何内容。
如果我这样打印值
print(self.dict["totalTrips"]!)
它成功打印了整数值
但是如果我这样做
print(self.dict["totalTrips"]! as? String)
它打印nil
所以我发现通过将一个值转换为字符串,它会打印 nil。所以问题是我如何在接受字符串值的标签中设置值
字典结果是这样的
{
totalTrips = 2;
}
最佳答案
试试这个
cell.totalTripsLabel.text = String(self.dict["totalTrips"]!)
关于ios - 在表格单元格中动态设置标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36325557/