I would like to call reloadData
method of TableView
when i return in foreground. My TableView
is built programmatically.
In FirstViewController
i've the methods to populate the TableView
and the function reloadListOfApps
where i call reloadData
methods.
class FirstViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, MFMailComposeViewControllerDelegate {
@IBOutlet weak var listOfApps: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
listOfApps.delegate = self
listOfApps.dataSource = self
}
func reloadListOfApps() {
listOfApps.reloadData()
}
// ================ TABLE DELEGATE/MANAGER ===================
let apps = ListAppClass.listApp()
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return apps!.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let bundle = apps! [indexPath.row]
let bundle_temp = String(describing: bundle)
cell.textLabel?.text = bundle_temp
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Current Cell!")
}
}
In AppDelegate
i've
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
FirstViewController().reloadListOfApps()
}
When i run the app i've this error
Fatal error: Unexpectedly found nil while unwrapping an Optional value
Reading some questions i've also check the Outlets in Storyboard, and seems all ok.
Hooks
correspond to FirstViewController
Where is the error?