Hello World Application

Let's start our first project. What is a better way to start than the all-time classic Hello World application. First Create a new project with the Single View Application template. In the project settings dialog enter project name HelloWorld and Class Prefix Helloworld.

In this application, the storyboard file is named MainStoryboard.storyboard. When the app starts, the MainStoryboard.storyboard file is loaded and the initial view controller is instantiated from it.

On the left pane, the Project Navigator, select the Mainstoryboard.storyboard file. Now Xcode opens the storyboard file in the editor area. The scene that you see on the canvas is named Hello World View Controller Scene because it is managed by the HelloWorldViewController object in your application.

From the Object Pane drag a a label and a round rect button from  the list to the view. As you move UI elements within the view, dashed blue lines appear that help you align the items with the edges of the view and with each other. Double-click the label and change the name in Hello World. Double-click the button and enter the words "Click me".

Select the Assistant Editor button. This is the middle button from the Editor buttons on the upper-right side.This will open a code window with the source of HelloWorldViewController.h. Using Xcode, you can add an action to a UI element and set up its corresponding action method by dragging from the element on the canvas to the appropriate source file. To assign an Action to the Click me button we need to take the following steps:

  • Ctrl+click and drag from the Round Rect Button between the @interface and @end sections in HelloWorldViewController.h
  • A dialog Box Opens: Choose Action at the Connection drop-down box and enter buttonClicked as Name. Make sure that the Event pop-up menu contains Touch Up Inside.
  • Click Connect

Xcode has added the following action method declaration to the header file:

- (IBAction)buttonClicked:(id)sender;

When you look in the implementation file HelloWorldViewController.m Xcode has also added an stub implementation buttonClicked method

- (IBAction)buttonClicked:(id)sender { }

Enter the following code inside the buttonClicked method:


UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Hello World" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];

[alertView show];

Build and Run the Project with the upper-left Run button (or Press cmd+R). When you press the Click me Button , the following AlertView is shown:


Here is the description of the parameters that we passed to the initializer of the alert view:

  • title - The string that the alert view will display on the top.
  • message - The actual message that gets displayed to the user.
  • delegate - This is the optional delegate object that we pass to the alert view.
  • cancelButtonTitle - The string that will get assigned to the cancel button.
  • otherButtonTitles - Any other buttons that you want to haver appear on the alert view.

You can download the source code of this project