Trombone0904
Trombone0904

Reputation: 4258

table reload.data while enter foreground

good morning :)

i have a tableview controller with the following example data:

Test 1

20.05.2015

Test 2

13.07.2015

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

Answers (3)

Ryan
Ryan

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

Imtee
Imtee

Reputation: 1393

in Swift 3.1

NotificationCenter.default.addObserver(self, selector: #selector(YourViewController.appBecomeActive), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil )

Upvotes: 2

Dharmesh Kheni
Dharmesh Kheni

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

Related Questions