Reputation: 4258
good morning :)
i have a tableview controller with the following example data:
Test 1
Test 2
a function checking the date of the data. if the date == date today => font color = green
My Problem: Yesterday, the font color of data "Test 2" was black => OK i let the app go into background and open it today again. the color have to be green today, but it was black, too.
after i terminate the app and open it again, the color change to green. i have a TableLM.reloadData() in the ViewillAppear, but i dont work. i think, i have to reload the table in the function "applicationWillEnterForeground"
but TableLM is not known in the appdelegate.swift what can i do?
Upvotes: 3
Views: 2889
Reputation: 4884
AppDelegate has a function to handle this kind of situation.
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.
}
Invoke a notification in applicationWillEnterForeground
and reload the tableView
.
Upvotes: 0
Reputation: 1393
in Swift 3.1
NotificationCenter.default.addObserver(self, selector: #selector(YourViewController.appBecomeActive), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil )
Upvotes: 2
Reputation: 71854
Add this code in your viewDidLoad
method:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "appBecomeActive", name: UIApplicationWillEnterForegroundNotification, object: nil )
After that add this method which will reload your tableview when application will enter in foreground:
func appBecomeActive() {
//reload your Tableview here
TableLM.reloadData()
}
Upvotes: 6