Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView数据在滚动时消失_Ios_Swift_Uitableview - Fatal编程技术网

Ios UITableView数据在滚动时消失

Ios UITableView数据在滚动时消失,ios,swift,uitableview,Ios,Swift,Uitableview,每当我在表格视图中滚动时,单元格标签的文本就会消失 这意味着tableview数据将消失。我尝试将switch语句更改为if语句,但仍然不起作用。我更改日期格式的功能是原因吗 这是我的密码: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdent

每当我在表格视图中滚动时,单元格标签的文本就会消失 这意味着tableview数据将消失。我尝试将
switch
语句更改为
if
语句,但仍然不起作用。我更改日期格式的功能是原因吗

这是我的密码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "requestsCell", for: indexPath) as! RequestsTableViewCell

    let requesten = requestsList[indexPath.row]

    switch requesten.type {
    case "FLT" :
        cell.requestType.text = "Flight"
        let reqDateTimeDate = stringToDate(strdate: requesten.reqDate!)
        cell.requestDate.text = "\(dateFormatterPrint.string(from: reqDateTimeDate))"
        cell.fromDate.isHidden = true
        cell.toDate.isHidden = true
    case "DOF" :
        cell.requestType.text = "Day Off"
        let reqDateTimeDate = stringToDate(strdate: requesten.reqDate!)

        cell.requestDate.text = "\(dateFormatterPrint.string(from: reqDateTimeDate))"
        cell.fromDate.isHidden = true
        cell.toDate.isHidden = true
    case "VAC" :
        cell.requestType.text = "Vacation"
        let reqDateFrom = stringToDate(strdate: requesten.dateFrom!)
        let reqDateTo = stringToDate(strdate: requesten.dateTo!)
        cell.requestDate.isHidden = true
        cell.toDate.text = "To: \(dateFormatterPrint.string(from: reqDateTo))"
        cell.fromDate.text = "From: \(dateFormatterPrint.string(from: reqDateFrom))"
    default:
        cell.requestType.text = ""
    }

    return cell
}

您应该更好地设置代码,以便每个case语句都更改相同的属性。或者您需要重写
prepareforeuse
方法,以便每次将单元格重置为公共状态

查看您的代码-每个case语句都应指定以下属性:

  • requestType.text
  • requestDate.text
  • fromDate.isHidden
  • fromDate.text
  • 托达特·伊希登
  • toDate.text

您能给我更多关于prepareForReuse方法的信息吗?您是否在滚动时使用主线程重新加载表数据?