如何使用 Objective-C 创建公共类/方法?

发布于 2024-10-09 07:11:38 字数 241 浏览 0 评论 0原文

我们是一个开发 iPhone 应用程序的小组。这是我们第一次。我只是想知道实现公共类的简单方法,以便我的合作伙伴可以给我一个包含我需要在代码中使用的值的变量。它不一定是一个类,任何其他简单的解决方案都可以工作。

只是为了更清楚地表明,我的朋友在他的代码中有一个值,我需要使用它“使用我的代码”在屏幕上显示它。我所知道的是,一切都必须通过控制器类进行通信,在这种情况下,我需要实现的东西我的朋友必须能够调用它,给它值,然后我获取这个值并显示它。先感谢您!

we are a group working on an iPhone app. and its our first time. I just would like to know the easy way to implement a public class so that my partner can give me a variable that contains a value i need to use in my code. It doesn't have to be a class any other easy solution would work.

Just to make it more clear my friend has a value in his code that i need to use to display it on the screen "using my code". What i know is that everything has to communicate through a controller class which in this case the thing i need to implement my friend must be able to call it, give it the value then i take this value and display it. THANK YOU IN ADVANCE!

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

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

发布评论

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

评论(1

眉目亦如画i 2024-10-16 07:11:38

I. 只需在 .h 中创建一个属性

@property(非原子,保留)NSString *userName;

并在 .m 文件中

@synthesize 用户名;

文档此处

他可以在他的类中制定和委托协议,您需要将您的对象设置为他的类实例的委托并实现委托方法。当他拥有时,vale 将调用委托方法,您将在您的方法中接收它。

文档此处

I. Just make an property in .h

@property (nonatomic, retain) NSString *userName;

and in .m file

@synthesize userName;

Docs here

II. He can make and delegate protocol in his class, the you need to set your object to be the delegate of his class instance and implement the delegate method. When he has the vale will call the delegate method and you will recive it in your method.

Docs here

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