从另一个ViewController获取NSDate到titleForHeaderInSection [英] get NSDate into titleForHeaderInSection from another ViewController
问题描述
我有两个视图,第一个是日历,第二个是带有 tableView
的UIView;
我正在尝试从firstView显示所选日期。管理以在我的第二个视图的 ViewDidLoad
方法中获取所选日期。
I have two views, first one is with calendar and the second one is a UIView with a tableView
;
I'm trying to display the selected date from the firstView. Managed to get the selected date inside ViewDidLoad
method of my secondView.
我如何添加 NSDate
到我的 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
method?
How I add my NSDate
to my - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
method?
推荐答案
声明 @property(非原子,保留)NSDate * displayDate;
(或 strong
而不是在TableViewController上使用ARC时保留
(别忘了合成)。然后第一个视图可以设置TableViewController的属性,例如:
Declare an @property (nonatomic, retain) NSDate *displayDate;
(or strong
instead of retain
when using ARC) on your TableViewController (dont forget to synthesize). The first view can then set the property of the TableViewController, for example:
MyTableViewController *mtvc = [[MyTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
mtvc.displayDate = selectedDate;
...
然后,您可以使用<$ c从TableViewController中访问日期$ c> self.displayDate ,例如在 titleForHeaderInSection
中。
You can then access the date from within your TableViewController using self.displayDate
, for example in your titleForHeaderInSection
.
这篇关于从另一个ViewController获取NSDate到titleForHeaderInSection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!