在堆叠视图之间传递数据
在我的应用程序中,我有几个视图......其中一些视图是使用导航控制器推送和弹出的。在某些视图中,我有一个表视图,其中每个单元格本身就是一个视图,因此当选择单元格时,将执行此代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决这个问题的一种简单方法是:
然后在详细视图中:
我希望您知道如何创建属性,否则请给我留言。
One easy way to solve it is:
and then in the detail view:
I hope you know how to create properties, otherwise drop me a comment.