I put a Table View Controller and embed in to a Navigation Controller on IB. After that I create a WalletsTableViewController class with the following code:
class WalletsTableViewController: UITableViewController {
private var wallets = [Wallet]()
override func viewDidLoad() {
super.viewDidLoad()
fetchWallets()
}
private func fetchWallets(){
let managedObjectContext = AppDelegate.managedContext
let fetchRequest: NSFetchRequest<Wallet> = Wallet.fetchRequest()
do {
wallets = try managedObjectContext.fetch(fetchRequest)
} catch {
print(error.localizedDescription)
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection: Int) -> Int {
return wallets.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "WalletCell", for: indexPath)
let wallet = wallets[indexPath.row]
cell.textLabel?.text = wallet.name
return cell
}
}
I implement a persistent application that's why I have the fetchWallets() method and it works well. I can print the data to the console but the tableView doesn't want to show my elements. Moreover the implemented tableView() methods are not called. How can I fix this problem?
EDIT: tableView.reloadData() did not help
My bad... I did not delete the autoimplemented functions. This has solved my problem.