在堆叠视图之间传递数据

发布于 2024-10-21 18:14:08 字数 641 浏览 0 评论 0原文

在我的应用程序中,我有几个视图......其中一些视图是使用导航控制器推送和弹出的。在某些视图中,我有一个表视图,其中每个单元格本身就是一个视图,因此当选择单元格时,将执行此代码:

DetailView *detailViewController = [[Detailview alloc] initWithNibName:@"Detailview" bundle:nil];
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];

并且在详细视图中,当单击特定按钮时将执行此代码(例如后退/取消按钮):

[self.navigationController popViewControllerAnimated:YES];

我想要的是将数据从详细视图传递到它前面的视图(初始化它的视图)。到目前为止,我已经实现了一个名为“Globals.h”的类,在其中放置了我想要传递的数据,并在这些数据变量上使用“extern”以确保它对于许多类来说是全局的,并且它有效适当地。但我认为这不是适当的方式。还有其他好的方法吗?

提前致谢 :)

In my app, I've several views.. and some of these views are pushed and popped using the navigation controller. In some view, I have a table view, in which each one of its cells is a view itself, so when the cell is selected, this code is executed :

DetailView *detailViewController = [[Detailview alloc] initWithNibName:@"Detailview" bundle:nil];
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];

and in the detailview this code will be executed, when a specific button is clicked (e.g. back/cancel button):

[self.navigationController popViewControllerAnimated:YES];

What I want is passing data from the detailview to the view that precedes it(the view that initialize it). So far, I've implemented a class named "Globals.h", in which I put the data I want to pass, and uses "extern" on these data variables to ensure it'll be global to many classes, and it worked properly. But I don't feel that this is the appropriate way to do so. Is there any other good ways to do that ?

Thanks in advance :)

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

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

发布评论

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

评论(1

灯角 2024-10-28 18:14:08

解决这个问题的一种简单方法是:

DetailView *detailViewController = [[Detailview alloc] initWithNibName:@"Detailview" bundle:nil];
detailViewController.controller = self;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

然后在详细视图中:

self.controller.data = data;
[self.navigationController popViewControllerAnimated:YES];

我希望您知道如何创建属性,否则请给我留言。

One easy way to solve it is:

DetailView *detailViewController = [[Detailview alloc] initWithNibName:@"Detailview" bundle:nil];
detailViewController.controller = self;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

and then in the detail view:

self.controller.data = data;
[self.navigationController popViewControllerAnimated:YES];

I hope you know how to create properties, otherwise drop me a comment.

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