gpt4 book ai didi

ios - 我如何从解析中获取数字数据和日期数据并将其放入 UILabel?

转载 作者:可可西里 更新时间:2023-10-31 23:44:49 24 4
gpt4 key购买 nike

目前我想从解析数据库中检索createdAtprice,两者的数据类型都是NumberNSDate。检索到它后,我想传递给 UILabel,分别是 dateprice。现在的问题是,每当我尝试运行模拟器时,两个 UILabel 数据都不会显示,而字符串数据类型会显示。

我当前的代码

if let createdAt = object?["createdAt"] as? String {
cell.date.text = createdAt
}


if let priceTitle = object?["price"] as? String {
cell.price.text = priceTitle
}

最佳答案

对于日期,使用 NSDateFormatter.stringFromDate 方法,因此您的代码应该是:

if let createdAt = object?["createdAt"] as? NSDate {
let dateFormatter = NSDateFormatter()
var theDateFormat = NSDateFormatterStyle.ShortStyle
dateFormatter.dateStyle = theDateFormat
cell.date.text = dateFormatter.stringFromDate(createdAt)
}

关于ios - 我如何从解析中获取数字数据和日期数据并将其放入 UILabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30306415/

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