如何将UILabel的值绑定到实例变量? [英] How to bind value of UILabel to an instance variable?

查看:290
本文介绍了如何将UILabel的值绑定到实例变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完整的新手mac / objective-c。我的问题是:我想知道是否可以绑定一个UILabel文本到一个变量,而不需要手动设置文本时改变值。

I am a complete newbie to mac/objective-c. My question is: I wonder if it's possible to bind a UILabel text to a variable, while not having to manually set the text when value change.

例如,在Mac操作系统,当我打开一个新的Finder窗口并删除一个文件,然后任务栏中的全局可用空间正在改变。

For example, on Mac OS, when I open a new Finder window and delete a file, then the global free space in the taskbar is changing. And that value also change in all the "finder" that are open.

如何在Mac或iPhone上使用Objective-c复制这样的行为?我正在考虑UILabel,但我找不到与手动设置每个UILabel不同的方法。

How can I replicate such behavior using Objective-c, either on Mac or for iPhone ? I was thinking about UILabel, but I couldn't find a way different from manually set each UILabel.

感谢
Leonardo

thanks Leonardo

推荐答案

当前版本的iPhone操作系统(3.1)不支持绑定(例如你会发现在桌面Cocoa)。暂时,您将需要手动编写控制器粘贴,以保持UI与您的模型同步。

The current version of iPhone OS (3.1) does not support bindings (such as you would find in desktop Cocoa). For the time being, you will need to write the controller glue manually to keep the UI in sync with your model.

具体来说,您将添加一个 IBAction 方法,并连接 UILabel 以在内容更改时调用。

Specifically, you would add an IBAction method in your controller, and connect the UILabel to call it when the contents changes.

这个问题也包括在内:

  • Bindings using Interface Builder (for iPhone apps)

在Mac上,您将使用键值编码(KVC)并将标签绑定到IB中的对象控制器。绑定文档涵盖的内容非常详细:

On the Mac, you would use Key-Value Coding (KVC) and bind the label to an object controller in IB. The bindings documentation covers this in quite some detail:

  • http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html

这篇关于如何将UILabel的值绑定到实例变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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