mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-04-13 22:41:46 +08:00
Add Cell setup code to an StyledTableCell Extension (#797)
* Add Code Repository Cell extension file * Move cell setup code to an extension of a StyledTableViewCell * Add fatalError instead of force unwrap
This commit is contained in:
committed by
Ryan Nystrom
parent
66481af678
commit
306eea70ec
@@ -99,28 +99,12 @@ final class RepositoryCodeDirectoryViewController: UIViewController, UITableView
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
|
||||
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? StyledTableCell else {
|
||||
fatalError("Could not dequeueCell with identifier: \(cellIdentifier)")
|
||||
}
|
||||
|
||||
let file = files[indexPath.row]
|
||||
cell.textLabel?.text = file.name
|
||||
|
||||
cell.isAccessibilityElement = true
|
||||
cell.accessibilityTraits |= UIAccessibilityTraitButton
|
||||
let fileType = file.isDirectory
|
||||
? NSLocalizedString("Directory", comment: "Used to specify the code cell is a directory.")
|
||||
: NSLocalizedString("File", comment: "Used to specify the code cell is a file.")
|
||||
cell.accessibilityLabel = cell.contentView.subviews
|
||||
.flatMap { $0.accessibilityLabel }
|
||||
.reduce("") { "\($0).\n\($1)" }
|
||||
.appending(".\n\(fileType)")
|
||||
cell.accessibilityHint = file.isDirectory
|
||||
? NSLocalizedString("Shows the contents of the directory", comment: "")
|
||||
: NSLocalizedString("Shows the contents of the file", comment: "")
|
||||
|
||||
let imageName = file.isDirectory ? "file-directory" : "file"
|
||||
cell.imageView?.image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate)
|
||||
cell.imageView?.tintColor = Styles.Colors.blueGray.color
|
||||
cell.accessoryType = file.isDirectory ? .disclosureIndicator : .none
|
||||
cell.setup(with: file)
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user