在 Objective C 中的视图控制器之间传递对象 [英] Passing Object Between View Controllers in Objective C

查看:60
本文介绍了在 Objective C 中的视图控制器之间传递对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的基于 iPhone 视图的应用程序,我需要帮助.这是一个带有导航的基于视图的应用程序.在 4 个视图控制器之间切换的页脚栏.

I have a very simple iPhone view based application I need help on. It's a view based application with a nav. bar in the footer that switches between 4 view controllers.

我需要做的是将 UILabel 值从视图 2 传递到视图 4.UILabel 字段是在视图 2 中计算的值,但我希望它出现在视图 4 中(如果 5+5=10,我希望出现在视图控制器 4 中的 10,而不是视图控制器 2).

What I need to do is pass a UILabel value from view 2 to view 4. The UILabel field is a value calculated in view 2, but I want it to appear in view 4 (if 5+5=10, I want the 10 to appear in view controller 4, not view controller 2).

我该怎么做?有没有人有任何我可以查看的示例代码?我在 Apple 的文档和网上搜索了一段时间,但还没有找到任何有用的东西.请记住,我是一个真正的新手.说到开发.我刚开始学习!

How do I go about doing this? Does anyone have any sample code I can review? I've searched awhile in Apple's docs and online and haven't found anything helpful yet. Keep in mind I'm a real newb. when it comes to development. I'm just starting to learn!

提前致谢.

推荐答案

有几种方法.我可能只会在应用程序委托的界面中创建一个变量,然后更改它并在那里访问它.

There are a few ways. I would probably just have a variable created in the application delegate's interface and just change it and access it there.

NSObject *myVariableFromDelegate = [[[UIApplication sharedApplication] delegate] myVariable];

[[[UIApplication sharedApplication] delegate] setMyVariable:10];

这篇关于在 Objective C 中的视图控制器之间传递对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆