0

I have an app that has a UITableView and in my Cells I have UIImageViews and UILabels that change images/textColors for a day theme and a night theme (trying to be automatically set).

My issue is that I set the images and colors when the table is populated with cellForRowAtIndexPath and its during the day "theme", then if I reopen the app hours later in the night "theme" and the app is still in the "background" and not needing to be reloaded (ie viewDidLoad doesn't fire), the day "theme" shows until I scroll the UITableView and then the night "theme" shows when new cells are brought into view by scrolling.

How should I set the objects in my cells when changing around time of the day? I was thinking to use an NSTimer, but I'm not sure how to update the objects in my cells. I was also thinking about using the appropriate methods in the AppDelagate to set things in motion, but is there a way to force reloading the TableView?

Any suggestions?

2 Answers 2

0

you could call [tableView reloadData] when viewWillAppear is called. viewDidLoad will not occur often enough for you, what you really want is to refresh when the view is about to appear to the user.

You can also check for applicationWillEnterForeground on your app delegate and signal to your view controller to reload its tableview this way as well.

Sign up to request clarification or add additional context in comments.

4 Comments

I've added [tableView reloadData] to viewWillAppear and that does fire when I go back to that view controller from another view controller. So that solves that issue. However, I tried to also reload the data in applicationWillEnterForeground but I'm not doing it right. I tried MyViewController *vc = (MyViewController *) vc; [vc.tableView reloadData]; and I don't think it actually reloads the data. How do I do this in applicationWillEnterForeground`?
does a breakpoint in cellForRowAtIndexPath get hit when you enter foreground?
No. It doesn't seem to fire if I hit Home and then go back to the app. I don't think I'm launching the reloadData method properly. How do I do this properly in the applicationWillEnterForeground method?
I did some searching this is what I needed: stackoverflow.com/questions/5873450/… Thank you for the tip on viewWillAppear, as that solved another issue for me :-)
0

You need to use applicationWillEnterForeground: and call reloadData on your table view.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.