我正在使用正常的UIViewController中的UITableView。出於某種原因,我的TableView中頂部單元格的文本始終爲灰色。爲什麼頂部tableViewCell灰色?
我一直在試圖弄清楚是什麼導致該單元變灰,但不知道它是什麼。我的tableView中的數據來自於名爲的文件列表,該列表在viewWillAppear和viewDidAppear期間都會刷新。
爲什麼頂部單元格總是灰色的這個代碼?
(和它都沒事文件列表中,並用文件列表中很多事情發生)
//MARK: - TableView
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if fileList.count == 0 {
return 1
} else {
return fileList.count
}
}
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if fileList.count == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.isUserInteractionEnabled = false
cell.accessoryType = UITableViewCellAccessoryType.none
cell.textLabel?.text = "No documents found"
cell.textLabel?.textAlignment = .center
cell.textLabel?.textColor = UIColor.black
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.isUserInteractionEnabled = true
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.textLabel?.text = (fileList[indexPath.row])
cell.textLabel?.textAlignment = .left
cell.textLabel?.textColor = UIColor.black
return cell
}
}
}
單元格的文本顏色是灰色的了。還有一堆其他代碼 - 它檢索用戶文檔目錄中的文件列表(如果啓用iCloud Drive,則從應用程序的無處不在容器中),該文件用於填充tableview。除了我在上面分享的擴展之外,沒有什麼能夠對tableview或其單元格做任何事情。 – Grant
@Grant和它的唯一灰色的第一個單元格沒有任何其他? –
是的,它只是第一個單元格 – Grant