plist 数据到第二个视图

发布于 2024-09-12 14:23:50 字数 192 浏览 6 评论 0原文

我有一个 plist (字典类型),在一个视图上填充文本视图和标签。我想在第一个视图上有一个信息 UIButton,它链接到一个单独的视图并显示来自同一 plist 的一些数据。

但它必须是来自 plist 中同一记录的数据。

我一切正常,但我坚持将数据传递到第二个视图。

非常感谢任何提示/帮助,

谢谢,

I have a plist (dictionary type) populating text views and labels on one view. I would like to have an info UIButton on this first view that links to a separate view and displays some data from the same plist.

it has to be data from the same record in the plist though.

I have everything working, but I'm stuck at being able to pass that data to the second view.

any hints/help is greatly appreciated,

thanks,

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

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

发布评论

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

评论(3

メ斷腸人バ 2024-09-19 14:23:50

或者您可以在信息视图中创建一个属性。

@property(nonatomic, keep)NSDictionary *myDic;

当您创建 Info 视图时,将带有数据的字典传递给第二个视图,然后第二个视图将显示数据。 ;-)

Or you could make a property in the info view.

@property(nonatomic, retain)NSDictionary *myDic;

And when you create the Info view, pass your dictionary with the data to the second view, which then displays the data. ;-)

故人如初 2024-09-19 14:23:50

您可以在下一个视图中打开相同的 plist 并以相同的方式读取数据:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

您可以为您的字典创建一个 Singleton 访问器类,并让两个视图都请求它的实例来访问相同的数据。

或者,如果您以编程方式创建视图,则可以在新视图控制器中创建一个设置器,并从原始视图控制器传递字典的引用。

You could open the same plist in the next view and read the data in the same way:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

You could make a Singleton accessor class for your dictionary and have both views request an instance of it to gain access to the same data.

Or if you create your views programmatically, you could just create a setter in your new view controller and pass a reference of your dictionary from the original view controller.

童话 2024-09-19 14:23:50

您可以在第二个视图的 .h 文件中创建一个 NSDictionary,然后当您移动到下一个视图时,设置您想要作为该字典传递的字典。

SecondView* view = [SecondView .......
view.passedDictionary = currentDict;
//then push the new view onto the screen

在第二个视图的.h文件中

NSDictionary* passedDictionary;
@property(nonatomic, retain) NSdictionary* passedDictionary;

You could just Create a NSDictionary in the .h file of the second view and then when you are moving to the next view set the dict you want to pass as that dictionary.

SecondView* view = [SecondView .......
view.passedDictionary = currentDict;
//then push the new view onto the screen

In the .h file of the second view

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