how to send a NSDate to another view

2019-08-28 09:00发布

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...

2条回答
乱世女痞
2楼-- · 2019-08-28 09:18

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

查看更多
狗以群分
3楼-- · 2019-08-28 09:20
  1. Make a property in another view. Then anoterView.date = myDate;
  2. Use global variable which accessible in both views ().
查看更多
登录 后发表回答