Guest User

Untitled

a guest
May 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import UIKit
  2.  
  3. class BackupViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  4.  
  5. var rows:[String] = []
  6. var showFiles = true
  7.  
  8. @IBOutlet weak var table: UITableView!
  9.  
  10.  
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. self.table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
  14. self.table.dataSource = self
  15. self.table.delegate = self
  16. getFiles()
  17. // Do any additional setup after loading the view.
  18. }
  19.  
  20. func getFiles() {
  21. let filemgr = FileManager.default
  22. let path = filemgr.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).last
  23. do {
  24. rows = try filemgr.contentsOfDirectory(atPath: (path?.path)!)
  25. // process files
  26. } catch {
  27. print("Error while enumerating files")
  28. }
  29. /*for file in files {
  30. rows.append(file.absoluteString)
  31. }*/
  32. showFiles = true
  33. }
  34.  
  35. override func didReceiveMemoryWarning() {
  36. super.didReceiveMemoryWarning()
  37. // Dispose of any resources that can be recreated.
  38. }
  39.  
  40.  
  41. func numberOfSections(in tableView: UITableView) -> Int {
  42. return 1
  43. }
  44.  
  45. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  46. return rows.count
  47. }
  48.  
  49.  
  50.  
  51. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  52. let cell:UITableViewCell = self.table.dequeueReusableCell(withIdentifier: "cell") as! UITableViewCell
  53. cell.textLabel?.text = rows[indexPath.row]
  54. return cell
  55. }
  56.  
  57.  
  58.  
  59. /*
  60. // MARK: - Navigation
  61.  
  62. // In a storyboard-based application, you will often want to do a little preparation before navigation
  63. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  64. // Get the new view controller using segue.destinationViewController.
  65. // Pass the selected object to the new view controller.
  66. }
  67. */
  68.  
  69. }
Add Comment
Please, Sign In to add comment