使用Interface Builder绑定(适用于iPhone应用程序) [英] Bindings using Interface Builder (for iPhone apps)

查看:95
本文介绍了使用Interface Builder绑定(适用于iPhone应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Interface Builder绑定iPhone SDK控件(比如UISlider)?

How does one bind an iPhone SDK control (say a UISlider) using Interface Builder?

与常规Cocoa应用程序不同,当使用Interface Builder打开iPhone-app XIB时,绑定选项卡似乎不存在

Unlike regular Cocoa applications, the bindings tab does not seem to be present when the iPhone-app XIB is opened using Interface Builder

推荐答案

在viewcontroller .h文件中将控件声明为IBOutlet。在IB中,将视图的文件所有者设置为viewcontroller类(选择文件的所有者,在Inspector窗口中单击(i)按钮并将类设置为viewcontroller)
现在选择文件所有者,单击检查器窗口中带有白色箭头的蓝色按钮。将您的UISlider的IBOutlet绑定到视图上的UISlider。

Declare the control as an IBOutlet in your viewcontroller .h file. In IB, set the File's Owner for the view as your viewcontroller class (Select File's owner, in Inspector window click on the (i) button and set the class as your viewcontroller) Now with the File's Owner selected, click on the blue button with a white arrow in the Inspector window. Bind the IBOutlet for your UISlider to the UISlider on your view.

要在滑块更改时获取滑块的值,请在viewcontroller中创建一个返回类型为IBAction的方法。在检查器窗口中,如果将其连接到UISlider,它会为您提供多个选项供您选择。选择已更改值选项。现在,每次更改滑块的值时,都会调用IBAction方法。

To get the value of the slider when it changes, create a method in the viewcontroller with the return type IBAction. In the inspector window, if you connect this to the UISlider, it gives you multiple options to select from. Select the "Value changed" option. Now every time the value of the slider is changed your IBAction method will be called.

希望有所帮助。

这篇关于使用Interface Builder绑定(适用于iPhone应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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