Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bindings using Interface Builder (for iPhone apps)

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

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

like image 543
Debajit Avatar asked Dec 26 '08 22:12

Debajit


2 Answers

Cocoa bindings is not available in the iPhone SDK. You have to do everything "by hand" much as you used to have to do on the Mac.

like image 117
Stephen Darlington Avatar answered Oct 11 '22 02:10

Stephen Darlington


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.

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.

Hope that helps.

like image 37
lostInTransit Avatar answered Oct 11 '22 03:10

lostInTransit