Saturday, July 12, 2014

Design Programming with Apple SDK - Part 5

Go back Design Programming with Apple SDK - Part 4

Making the objects work Together - Creating the Outlet Connection

First make sure that the storyboard canvas is visible and that the TestProjectViewController.h file is still open in the Assistant editor. Click the Label on the canvas. Then control-drag from the Label to the TestProjectViewController.h file method declarations area. It does not matter if the declaration is placed above or below the one we previously created. Make sure that the Connection says Outlet; the name is textLabel; the Type is UILabel; and the Storage is Weak. Then click Connect.

Making the objects work Together - Creating a Variable

Now we have added an outlet to out View Controller file. We are almost ready to fill-in our action changeText: method. But first we will define a variable that will count the number of times the button has been pressed.

Add the following line of code to the TestProjectViewController.h file:
@property (nonatomic, assign) NSInteger number;
Then in our TestProjectViewController.m file, below the @implementation TestProjectViewController add:
@synthesize number;
Then in the viewDidLoad method add number=0; to make the method look like this:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
number = 0;
}
In the preceding steps we initialized our number variable to 0.

Read Next - Design Programming with Apple SDK - Part 6

No comments: