Question

I am new to iOS programming however I have extensive experience in Swing, WinForms, WPF & HTML/CSS/Javascript.

I have dropped a UIImageView onto a story board and set the initial image using the attributes inspector. So far this is the same as with NetBeans or VisualStudio.

However when I open the view controller for the storyboard there is no reference I can see for the UIImageView for me to programmatically manipulate.

In NetBeans (Swing) or VisualStudio (WinForms or WPF) there would be a variable created in the 'code behind.'

My specific question is how to I get a reference to the UIImageView to manipulate via Objective C.

Was it helpful?

Solution

To enable your code to send messages to a user interface object, create a connection from the user interface object to an outlet in your code. The easiest way is to control-drag from the object in Interface Builder to the implementation file in the assistant editor.

enter image description here

Apple has an excellent article with screenshots here: Creating an Outlet Connection

OTHER TIPS

The great thing about XCode and Storyboarding is the "Suit and Tie" editor. This editor allows you to connect your storyboard's elements directly into your code. Simply open your UIViewController's class, control-click on an element, and drag directly into your code.

If you don't enjoy that, you can manually add a UIImageView property in your .h file, and connect it from there.

@property (nonatomic, retain) UIImageView *myImage;

Go into your ViewController's "Connections Inspector" and drag "myImage" onto your UIImageView element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top