how to send a NSDate to another view

2019-08-28 09:27发布

问题:

How do I send a NSDate object to another view?

Trying to get the selected date form a calendar (Si-Calendar) and use it into another view...

回答1:

Looking at the README file on GitHub, changes in the selected date will be sent to the object you set as delegate for the CalendarViewController object. The method that will be called is:

- (void)calendarViewController:(CalendarViewController *)aCalendarViewController dateDidChange:(NSDate *)aDate

If you then want to pass that date on to a new viewController, make sure it has an NSDate property, let's say it goes by the name date. You can then pass the date to the other viewController (let's say it's called otherViewController) this way:

otherViewController.date = aDate;

This is a normal way of passing objects through viewControllers, you'd do it like this for any type of object. The basic idiom is:

  1. Have a property of the type of object you want to pass in the viewController you want to pass it to
  2. Set the property. If it was defined with the retain or strong keyword, it'll be retained.

That's all! Hope this helps



回答2:

  1. Make a property in another view. Then anoterView.date = myDate;
  2. Use global variable which accessible in both views ().