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