从另一个 ViewController 获取 NSDate 到 titleForHeaderInSection

发布于 2024-12-17 15:11:22 字数 274 浏览 4 评论 0原文

我有两个视图,第一个是日历,第二个是带有 tableView 的 UIView; 我正在尝试显示从第一个视图中选择的日期。设法在我的 secondaryView 的 ViewDidLoad 方法中获取所选日期。

如何将我的 NSDate 添加到我的 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 方法?

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.

How I add my NSDate to my - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔纱相望 2024-12-24 15:11:22

在 TableViewController 上声明一个 @property (nonatomic, keep) NSDate *displayDate; (或者在使用 ARC 时使用 strong 而不是 retain)(不要忘记来合成)。然后,第一个视图可以设置 TableViewController 的属性,例如:

MyTableViewController *mtvc = [[MyTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
mtvc.displayDate = selectedDate;
...

然后,您可以使用 self.displayDate 从 TableViewController 中访问日期,例如在 titleForHeaderInSection 中。

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

You can then access the date from within your TableViewController using self.displayDate, for example in your titleForHeaderInSection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文