Skip to content
Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
Close

Search

Home/Software Development/Development tools/Apple iOS development/Create an iPhone, iPod or iPad app – Part 3 – Make it work
Apple iOS development

Create an iPhone, iPod or iPad app – Part 3 – Make it work

By Laszlo Pinter
August 11, 2013 3 Min Read
0

In this article we will make our application work. We already created a simple application and added a Text field, a Label and a Button to the view. We created connections between the user interface elements and the View Controller.

To make more room to work, close the Utilities area by clicking the Utilities button in the View group in the upper right corner of the screen or in the View -> Utilities menu click Hide Utilities

Create a Property to store your name

To be able to work with the data entered into the text field we have to create a property to store it and make it available for other processes. The property is a placeholder where we store values.

  • In the project navigator on the left side of the screen select the …ViewController.h
  • Before the @end statement write the following:
    @property (copy, nonatomic) NSString *userName;

You can copy the text into the editor, but if you choose to type it, Xcode will help you to complete the words. Just hit Return to accept the suggestions.

xcode inline suggestion

As you continue to type Xcode will show selection lists to help you. Use the arrow keys to select the appropriate item and press Return.

xcode completion list

Make the button work

In the previous article, Part 2,we already connected the button to the controller, now we will tell the controller what to do when the user clicks the button.

    • In the project navigator on the left side of the screen select the …ViewController.m item
    • Scroll down to the bottom to see the implementation of the changeGreeting: method at the end of the @implementation section
    • Add lines to the method, it should look like the text below. The first and last lines (the method definition and the closing bracket) are already there, to overwrite them copy the text below, select the first and last line in the editor and replace them with the full text.
- (IBAction)changeGreeting:(id)sender {

    self.userName = self.textField.text;

    NSString *nameString = self.userName;
    if ([nameString length] == 0) {
        nameString = @"World";
    }
    NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
    self.label.text = greeting;
}

You can run your app now to make sure all parts are correct, but it is not done yet.

  • Click the button on the simulated screen and  “Hello, World!” should appear in the the label.
  • If you click the text field you can enter letters there, but there is no way yet to close the automatically appearing keyboard

Make the keyboard disappear

The text field cannot close the keyboard, but it can ask the View Controller to act in behalf of it, so we will delegate the work to the View Controller

  • Stop the simulator by clicking the Stop button in the upper right corner of the screen

Teach the View Controller what to do

  • Select the …ViewController.m in the project navigator on the left side of the screen
  • At the bottom of the file before the @end statement enter the following. The easiest way to to this is to copy and paste the code.
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == self.textField) {
        [theTextField resignFirstResponder];
    }
    return YES;
}

In the method the resignFirstResponder instruction will close the keyboard.

Set up the View Controller to work on behalf of the text field

  • In the project navigator select the …ViewController.h item
  • To the end of the @interface line add the following:  <UITextFieldDelegate>The line should look like this:
    @interface HelloWorldViewController : UIViewController <UITextFieldDelegate>

    If there is already something between the < and > signs, just add ,UITextFieldDelegate starting with a comma (,) between the < and > signs.

 

Test your application

  • Click the Run button in the upper right corner of the screen

The application should behave as you expect it:

  • When you click the text field the keyboard appears
  • When you enter your name the letters show up in the text field
  • When you click the Done button on the keyboard the keyboard disappears
  • When you click the button on the screen “Hello, your name” appears in the label

Congratulations, you just created your first working iPhone, iPod, iPad app!

Tags:

iOSiPadiPhoneiPodXcode
Author

Laszlo Pinter

Follow Me
Other Articles
Previous

Create an iPhone, iPod or iPad app – Part 2 – Adding User Interface elements

Next

Create an iPhone, iPod or iPad app – Part 4 – Deploy the app to an Apple device

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Last Changes

  • DevOps Engineering part 1. (Mac) - Make your Macintosh easier to use June 25, 2026
  • Japan travel tips June 22, 2026
  • How to stop the rain and snow in Cities: Skylines II June 20, 2026
  • Cities: Skylines II Developer Mode June 20, 2026
  • 'CSII_MANAGEDPATH' has incorrect path(s) when building Cities: Skylines II mod June 20, 2026

Tags

.NET .NETcore 3Dprinting ASP.NET Core AutodeskInventor AWS C# Chef cloud DevOps Docker EntityFramework Games Git Go iOS iPad iPhone iPod Java Kubernetes Linux MacOSX MSSQL MVC Node.js Packer PowerShell Python RDS RightScale Ruby security Splunk TeamCity Terraform TestKitchen Tomcat Ubuntu Vagrant VirtualBox VisualStudio Windows WordPress Xcode

Recent Comments

  • Zengei László on MyHeritage családfa exportálása és küldése emailben
  • Raúl Castillo on DynDns update error
  • MICHAEL on Windows Media Player 12 cannot find the album information
  • Nargis on Configure Epson ET-3850 scanning on Windows 11
  • Venczelné Zemen Erika on Delta S2302 termosztát programozása

–

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright 2026 — Pinter Computing. All rights reserved.