2017-08-14 5 views
0

私は通常の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 
    } 
} 

} 

答えて

0

あなたのコードを実行中の問題はありませんが、それは私のために罰金実行しています。

cell.selectionstyle = .greyを設定しても、セルまたはテキストに灰色が表示されません。

質問についてもっと明確にする必要があります。

1)グレーとは何ですか?テキストカラーまたはセルカラー。

2)隠れている、または離れているコードは何ですか?

extension ViewController : UITableViewDelegate,UITableViewDataSource{ 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 
     return fileList.count 
    } 


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell") 
     let rowData = fileList[indexPath.row] 
     cell?.textLabel?.text = rowData 
     //cell?.isSelected = true 
     cell?.selectionStyle = .gray 
     cell?.isUserInteractionEnabled = true 
     cell?.accessoryType = UITableViewCellAccessoryType.disclosureIndicator 
     cell?.textLabel?.textAlignment = .left 
     cell?.textLabel?.textColor = UIColor.black // if let priceString = rowData[2] as? String { cell.priceLabel.text = "Price: $(priceString)" } 
     return cell! 
    } 

    // Number of sections in table 

    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    }// Default is 1 if not implemented 


} 
+0

後のセルのテキストの色がグレーです。他にもたくさんのコードがあります。ユーザーのドキュメントディレクトリ(またはiCloudドライブがオンの場合はアプリのユビキタスコンテナ)からファイルのリストを取得します。このリストはテーブルビューの読み込みに使用されます。上記で共有した拡張機能以外は、テーブルビューやそのセルに何もしません。 – Grant

+0

@Grantとその最初のセルの唯一のグレーは他にありませんか? –

+0

はい、最初のセルだけです – Grant

0

これは、上記の問題hereと同じだと思います。設定してみてください:

cell?.textLabel?.isEnabled = true` 

fileList.count == 0ためのif文ブロックにライン

cell.isUserInteractionEnabled = false 
関連する問題