我正在使用正常的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