0

I'm writing a calendar app, now I have weekView, weekViewController, dayView, dayViewController, monthView, monthViewController.

what I want to do is that: when you select a date in any view, then switch to another view, I want the new view will show the same date, too.

I've managed to share the selected date among the controllers, but I don't know how to tell the view update their content every time they show?

Jerrylk
  • 379
  • 5
  • 19
  • see http://stackoverflow.com/questions/6162211/iphone-ios-will-there-be-called-any-method-if-a-uiview-is-added-as-a-subview – danh May 07 '13 at 01:12

1 Answers1

0

Try placing the date updating logic in the - (void)viewWillAppear:(BOOL)animated methods of the view controllers. Here is the reference.

Stunner
  • 12,025
  • 12
  • 86
  • 145
  • Thank you, viewWillAppear is the right way, but there are still problems: I use a UITabBarController to contains all the three controllers, and use tabBarController:didSelectViewController to get the selected date from previous controller, and set in the next coming controller. But I found that the viewWillAppear was called before the select date setting, so In fact the UIView stays the same. – Jerrylk May 07 '13 at 01:24
  • I would recommend you make a global singleton object that is accessible by all view controllers which holds the date value, and read the date value from that singleton object in the `viewWillAppear:` method. This is much cleaner than your approach. – Stunner May 07 '13 at 06:00
  • @Jerrylk if this answer helped solve your issue, please mark it as the answer (check-mark below the up/down vote arrows). – Stunner May 08 '13 at 20:32