O'Reilly logo

Xcode 4 iOS Development by Steven F. Daniel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – declaring input field as a property of View Controller

If we wanted to declare the userName instance of the UITextField, we would do it as follows:

  1. Declare it as a property in the header file of our View Controller as shown below:
    @property (retain, nonatomic) NSString *userName;
    
  2. We will then need to use the @synthesize directive in the implementation file of our View Controller class, to create the getters and setters as shown below:
    @synthesize userName;
    
  3. Once we have added these lines, we are then able to retrieve the value from our userName text property by using:
    theUserName = userName.text;
    
  4. If we wanted to assign something to this object, we can do so as follows:
userName.text = @"Joe Bloggs";

What just happened?

In this section, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required