Saturday, July 12, 2014

Design Programming with Apple SDK - Part 6

Go back Design Programming with Apple SDK - Part 5

Making the objects work Together - Filling in our Method

After initializing our number variable, we can count each time the button is pressed. We can add the code to our changeText method to make it look like this:
- (IBAction)changeText:(id)sender {
    number++;
    if (number == 1) {
        NSString *text = [[NSString alloc] initWithFormat:@”The button has been pressed 1 time”];
        self.textLabel.text = text;
    }
    else{
        NSString *formattedNumber = [NSString stringWithFormat:@”%d”, number];
        NSString *text = [[NSString alloc] initWithFormat:@”The button has been pressed %@ times”,
        formattedNumber];
        self.textLabel.text = text;
    }
}
Now we can test the project in the Simulator to see what we have done. Before the button is pressed, we should see the words, “The button has not been pressed.” Then after the button is pressed for the first time the Label should read, “The button has been pressed 1 time.” On successive presses of the button we should see “The button has been pressed X times,” where X is the actual number of times the button has been pressed.

Running the App on a Physical Device

If we want to run our App on a physical device, we have to sign up to the paid iOS Developer Program.You can sign up here:
https://developer.apple.com/programs/ios/.

Then you will need to work through the Development Provisioning Assistant on the Apple website. The process will involve getting a Developer Certificate from Apple and then setting-up a Provisioning Profile. After this is set-up, you should be able to select your development device from Xcode to test on your device instead of on the iOS Simulator.

Read Back - Design Programming with Apple SDK - Part 1

No comments: