我将时间戳转换为普通类型,但我收到此错误---无法调用类型' Double'的初始值设定项。使用类型'([Int])'的参数列表,如何解决?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "jobCell", for: indexPath)
//print jobTime = 1504753200
let unixTimestamp = Double(jobTime) //error here
let date = Date(timeIntervalSince1970: unixTimestamp)
cell.textLabel?.text = "\(jobTime[indexPath.row])-\(jobEndTime[indexPath.row])"
return cell
}
我正在检索JSON数据并放入表格视图单元格
var jobTime = [Int]()
var jobEndTime = [Int]()
viewDidLoad中
guard let jobs = json["jobs"] as? [[String:Any]] else {return }
for job in jobs {
if let id = job["jobTime"] as? Int{
self.jobTime.append(id)
}
if let id = job["jobEndTime"] as? Int{
elf.jobEndTime.append(id)
}
}
self.tableView.reloadData()
}
答案 0 :(得分:0)
试试这个 -
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "jobCell", for: indexPath)
//print jobTime = 1504753200
let unixTimestamp = Double(jobTime[indexPath.row]) //Change here
let date = Date(timeIntervalSince1970: unixTimestamp)
cell.textLabel?.text = "\(jobTime[indexPath.row])-\(jobEndTime[indexPath.row])"
return cell
}