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?

chis54
  • 477
  • 5
  • 17

2 Answers2

0

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

rdelmar
  • 103,982
  • 12
  • 207
  • 218
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.

foggzilla
  • 1,705
  • 11
  • 15
  • 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`? – chis54 Nov 11 '12 at 17:04
  • does a breakpoint in cellForRowAtIndexPath get hit when you enter foreground? – foggzilla Nov 11 '12 at 18:07
  • 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? – chis54 Nov 11 '12 at 21:19
  • I did some searching this is what I needed: http://stackoverflow.com/questions/5873450/calling-method-in-current-view-controller-from-app-delegate-in-ios Thank you for the tip on `viewWillAppear`, as that solved another issue for me :-) – chis54 Nov 11 '12 at 22:03