繁体   English   中英

快速iOS详细信息中的TableView

[英]tableview in swift ios detailTextLabel

我正在为iPhone创建带有Swift的Todo应用程序。 我希望tableview在tableview中显示任务的名称和时间。 Textlabel显示正确的任务名称,而detailTextLabel仅显示Detail,而不显示时间。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {      
   var cell = tableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell!   
    let task = tasks[indexPath.row]        

    if task.done {

        cell?.textLabel!.text = "‼️\(task.name!)"
        task.time = cell!.detailTextLabel!.text
    } else {            
        cell?.textLabel!.text = "\(task.name!)"
        task.time = cell!.detailTextLabel!.text
    }        
    return cell!
}

您对detailTextLabel的分配是向后的。

if task.done {

    cell?.textLabel!.text = "‼️\(task.name!)"
    cell!.detailTextLabel!.text = task.time
}
else {

    cell?.textLabel!.text = "\(task.name!)"
    cell!.detailTextLabel!.text = task.time

}

您实际上从未将详细信息标签文本设置为任何内容。 您需要使用以下内容进行设置:

cell?.detailTextLabel!.text = task.time.longStyleDateString

这是日期扩展名:

extension Date { var longStyleDateString: String { let formatter = DateFormatter() formatter.dateStyle = .long return formatter.string(from: self) } }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM