Я создал UIViewController, содержащий UITableView.Я хочу, чтобы он отображал файлы, которые я создал в другой позиции.
Соответствующий класс выглядит следующим образом:
import UIKit
class BackupViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var rows:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
self.table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.table.dataSource = self
self.table.delegate = self
getFiles()
// Do any additional setup after loading the view.
}
func getFiles() {
let filemgr = FileManager.default
let path = filemgr.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).last
do {
rows = try filemgr.contentsOfDirectory(atPath: (path?.path)!)
// process files
} catch {
print("Error while enumerating files")
}
table.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rows.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell = self.table.dequeueReusableCell(withIdentifier: "cell") as! UITableViewCell
cell.textLabel?.text = rows[indexPath.row]
return cell
}
@IBOutlet weak var table: UITableView!
}
Он читает файлы правильно и когда
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)
вызывается (что происходит 3 раза по какой-то причине), массив имеет (на данный момент) 2 элемента.Однако функция
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
никогда не вызывается, и, конечно, я получаю пустую таблицу.