You are on page 1of 40

Beginning Your iPhone Programming Journey

An Introductory Chapter from EDUmobile.ORG


iPhone & iPad Development Training Program

(now with a bonus chapter on iPad Development)

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


NOTICE: You Do NOT Have the Right
to Reprint or Resell This eBook!

You Also MAY NOT Give Away,


Sell or Share the Content Herein

Copyright © 2009 – 2010 EDUmobile.ORG

ALL RIGHTS RESERVED.

No part of this ebook may be reproduced or transmitted in any form whatsoever,


electronic, or mechanical, including photocopying, recording, or by any informational
storage or retrieval system without the expressed written, dated and signed
permission from the author.

LIMITS OF LIABILITY / DISCLAIMER OF WARRANTY

The authors and publisher of this book have used their best efforts in preparing this
material. The authors and publisher make no representation or warranties with
respect to the accuracy, applicability, fitness, or completeness of the contents of this
program.

They disclaim any warranties (expressed or implied), merchantability, or fitness for


any particular purpose. The authors and publisher shall in no event be held liable for
any loss or other damages, including but not limited to special, incidental,
consequential, or other damages.

This manual contains material protected under International and Federal Copyright
laws and Treaties. Any unauthorized reprint or use of this material in prohibited.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Beginning Your iPhone Programming Journey

Every once in a while a new opportunity arises due to a revolutionary


technology and business model which is years ahead of the current scenario.

Apple has done exactly that with its iPhone and iPod products, content delivery
mechanism and business model that has leveled the playing field between big,
small and individual businesses.

Those of us who move quickly to learn the technology are the ones who will
benefit the most from it, before ideas are taken by others and before the
market gets too saturated, making it harder to succeed.

You may have a very exciting idea and a passion to learn the tricks of coding
like the gurus, but the due to limited iPhone development tutorials online and
lack of well structured courses, your journey may probably not take off at all.
As a result, your idea that could become the next blockbuster application on
the App Store – will never happen and remain just a dream.

And, its not really your fault… as there are currently no affordable online
iPhone development courses that teach you through real tutors who guide you
through step by step.

This is where the iPhone Course offered at EDUmobile.ORG comes in…

Over a period of 12 weeks you will learn the topics step by step and start
coding like the iPhone gurus. We will teach you through the following mediums -

Weekly Online Videos that you can download and view at your convenience

Access to Real Tutors to help you solve coding or conceptual issues, on a


one-on-one basis

Weekly Worksheets and Exercise for you to do with challenging examples


that are set up with just the right learning curve

Access to an Online Form for discussing issues and meeting other students.

One or Two Live industrial projects at the end of the course

Plus you get a full 30 days no questions asked full money back guarantee.

All this said, now lets get started …

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


First things first… is the iPhone Programming Course
right for me?

Before starting your journey, you must understand what is needed and
expected of you to finish the course successfully.

If you have absolutely no knowledge of programming, it will be very hard –


although not impossible. Since, this is a programming course, you will be better
prepared if you have programmed before – in any language.

It does not matter if you programmed in Java, C or Scripted websites. As long


as you know the basics you are good to go.

However if you are not a programmer, but are up to the challenge, then you
must ask yourself if you will be programming yourself - or will you go through
this course to eventually become a producer for an iPhone product.

All said - a very basic knowledge of programming is a must.

I suggest that you try to learn just basic C or python to quickly learn the
programming nuances and concepts.

If you are from a completely non-programming background, you may need a


week to 1 month to catch up with the basics depending on the time you spend
on learning.

So, in order to get started comfortably with this course, you should be able to
understand the following concepts before you go forward -

What are data types?

What are operators?

What are conditionals?

What are loops?

What are arrays and strings?

What are objects?

What are methods?

I’ll stop at that, for now. This should be more than enough.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


I suggest you know at least a few of the above, if not all, and they should not
sound completely alien to you! Of course, if you need to review some of these
concepts, you can continue brushing up your programming fundamentals in
parallel to the iPhone course.

Either way … you need to do some homework before you start the iPhone
Programming course!

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


How is the Course Structured?

The iPhone Course is structured to teach you and focus on the following -

Objective C

Cocoa Touch Framework

iPhone SDK

iPhone APIs

Objective C

Objective C is a programming language which will be used to program on the


iPhone. If you have programmed for Mac before you already know Objective C
and for those who are new Objective C you can think Objective C to be child of
C programming language and a distant cousin of C++.

It was developed by Brand Cox and Tom Love for their company StepStone.
According to Wikipedia Objective-C is a reflective, object-oriented
programming language, which adds Smalltalk-style messaging to the C
programming language. Now if you don’t understand what is reflective, object
oriented and messaging there is no need to panic.

It will be discussed soon and you will cross these mole hills before you actually
climb the mountain.

Cocoa Touch Framework

Cocoa touch is Apple's name for the collection of frameworks, APIs, and
accompanying runtimes that make up the development layer of iPhone OS.

By developing with the Cocoa touch frameworks you will be writing applications
the same way that iPhone OS itself is written, with controlled access to the the
operating system. You need to learn various aspects of the touch framework to
master the iPhone programming.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


iPhone SDK

The iPhone SDK consist primarily of Xcode and Interface Builder. The Xcode is
all season complete SDK for building MAC software. It has been extended to
support the iPhone and iPod programming.

The other tool that will be used very often is called the interface builder. It
helps creating faster interface for your application with minimal coding thus
reducing the development time considerably.

iPhone APIs

Additionally to Cocoa there are other libraries such as OpenGL es which you
need to learn to give your application that extra punch which can knock down
the competition.

The other iPhone specific components that you need to learn is SQLite , Core
animation, Accelerometer, phone and media playing APIs.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Understanding The iPhone SDK

The first thing we need to do to get started is to setup our coding environment
on our computer.

For this, we need to download and install the iPhone SDK on our Mac or the
Virtual OS on our Windows PC.

Installing the SDK

Download the SDK from http://developer.apple.com/iphone after registering


at the portal. The registration is free. If you want, you can optionally join the
developer program for $99 only, but we suggest you do that later.

Once the Xcode is installed, it will appear in the dock as shown below. You
need to click and start the Xcode to create your first application.

Alternatively, you can search for Xcode in Finder and can start things from
there.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Once Xcode is started, the following screen will be visible on your desktop…

Now, close the smaller window, and you are ready to start programming for
iPhone!

Next, do the following…. Access –

File >> New Project

… and a new project template window will be displayed as shown on the next
page, below -

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved
You will see that there are ready made templates for creating applications.

These templates are handy to use and more often than not, we will use
standard templates to create our applications.

However, if you do not need any hand holding and you want to create an
application from scratch, you may use the windows based application.

For our example today we will select …

“View Based Application”.

... and give a name to the Application as “Hello World” .

The following screens will appear…

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


However, before we start any work on our application we need to familiarize
ourselves with the Xcode IDE.

So what exactly is Xcode IDE ?

Xcode IDE primarily can be narrowed down to three major parts in addition to
the Menu. They are …

The Top Bar

The Side bar

The code editor

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


1. The Top Bar

This customizable bar provides shortcuts to menu elements, and looks like
this…

2. The Side Bar

This bar displays the directory structure of the current project. We will use it
more in a later part of our course. It looks like this …

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


3. The Code Editor

The other major part is the code editor. The content area is where you write
your code. You can access the files from the side bar by clicking them and it
will show up in the content window.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Application Architecture - A Sample Application

When we created the views based project, Xcode create lots of code and
component for us. Let us have a detailed look into this code.

If we click on the Classes folder on the left panel we will see the classes that
have been created by the Xcode.

These classes are…

Hello_WorldAppDelegate.h

Hello_WorldAppDelegate.m

Hello_WorldViewController.h

Hello_WorldViewController.m

These are all Objective C files, each playing a designated role in the project.

Through in this article we will not get into the details of these files but, for
clarity of purpose, we will define the work assigned to these classes.

We know that “.h” files in objective C are for deceleration and “.m” files have
the implementation details. So the two classes Delegate and View Controller
are also divided into respective “.h” and “.m” files.

The Delegate class is the class which listens to the Applications running. This
class actually starts the application and exists all through the life cycle of the
application.

In short you can consider the Delegate as the Shell which enables the
application. Application passes messages on to the delegate through its life
cycle which is handled and acted upon by it.

The View Controller is very specific to view based application that we have
selected. Before we discuss the View Controller we must tell you that View is
necessary to draw content on the iPhone.

In fact each iPhone Application has one window and can have multiple views. A
view is drawn over a window and in most of our practical applications we will
be dealing with views only.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


A view is something that is visible to user and the controller decides what
should be shown on the view.

This architecture is similar to the MVC architecture where we use model view
and controller components to create our application.

Auto Generated Code Example

Let us now have a detail look into the code generated by the Xcode. In order
for it to make any sense you must understand ObjectiveC.

However, even if you are not familiar with this, as of now, you can read
through it. We have briefly clarified most of the major concepts.

Before we look into the code let us just do a bit of Objective C.

Objective C is Objects added to C. It is quite different from C++ in terms of its


syntax and is rather similar to Smalltalk. However, it contains most of the
object oriented features like Data Encapsulation, Polymorphism and
Inheritance.

Now, let us talk about some important concepts which are there is the code
below

@interface - The interface in objective C is use to declare the methods and


data elements of the class.

@implementation - The implementation defines the methods that were


declared earlier using the interface.

@class - Declares the methods defined elsewhere. It is less memory intensive


than an #import statement and in a compact device like iPhone it will used
more often than mac applications.

@property and @synthesize - The property and synthesize directive add


getter and setter function to the class. A getter and setter function is use to
assign and obtain values to an object. When we use @synthesize we do not
have to explicitly define a get and set function for the object properties it just
get internally defined by the system.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


IBOutlet - It is a special instance variable that references another object. It
lets the Interface builder know of the object. We will discuss it in detail in
later weeks.

IBAction - It is the trigger which is called from an Interface builder UI object.

Now that you are familiar with the above concepts, here is the code snippet…

AppDelegate.h

@class Hello_WorldViewController;

@interface Hello_WorldAppDelegate : NSObject <UIApplicationDelegate> {


UIWindow *window;
Hello_WorldViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;


@property (nonatomic, retain) IBOutlet Hello_WorldViewController *viewController;

@end

Explanantion of the code above…

The Above delegate class starts with defining a class directive for view
controller.

As discussed above it does that to import the definitions from view Controller
class. The Next line uses a concept called as Protocol -

@interface Hello_WorldAppDelegate : NSObject <UIApplicationDelegate>

A protocol is list of methods shared between classes.

UIApplicationDelegate is the protocol and the NSObject is the parent class of


Hello_WorldAppDelegate.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Next, we create object of UIWindow and View controller.

Then, we make these objects properties.

The key words “nonatomic” and “retain” decides the way the object is stored
and accessed. We will talk about them a bit later.

This concludes our explanation of AppDelegate.h code.

Now, lets Move on to our Second code example

AppDelegate.m

#import "Hello_WorldAppDelegate.h"
#import "Hello_WorldViewController.h"

@implementation Hello_WorldAppDelegate

@synthesize window;
@synthesize viewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Override point for customization after app launch


[window addSubview:viewController.view];
[window makeKeyAndVisible];
}

- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}

@end

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Explanantion of the code above

We know that .m file is the implementation file.

We start by importing the “.h” files. This is required for the compiler to
relate the objects to the corresponding class.

We then synthesize the two properties we created earlier. Please note we


will have to synthesize any properties before using them.

We then find a method which is first called as soon as the application starts.
The method “ applicationDidFinishLaunching” is created automatically the
SDK. This starts the application with the root window.

It then adds the view on top of the window with the key word
“addSubview”.

As our view is being handled by the object viewController the system added
addSubview:viewController.view.

The next method dealloc is to free the memory occupied by the objects we
created.

Third Code Example Snippet

ViewController.h

#import <UIKit/UIKit.h>

@interface Hello_WorldViewController : UIViewController {

@end

Explanantion of the code above

Currently this class has very few lines and it just declares itself as an
interface.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Fourth Code Example

ViewController.m

#import "Hello_WorldViewController.h"

@implementation Hello_WorldViewController

////Some methods

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.


}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)dealloc {
[super dealloc];
}

@end

Explanantion of the code above …

Currently the code is not doing much except for being an empty
implementation file.

The methods that are there are empty and does not serve any purpose as of
now. We will now take this program to the next level adding an interface to
our application and we will do it by using Interface Builder.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Though it is possible to add interfaces without using Interface builder by
directly using the objective C code, but it greatly simplifies the development
process and reduces the time to a greater extent. Also, the aim of this article
is to make you familiar with IB - and so we will create our interface with
interface builder.

The “Interface Builder”


This is the interface creating utility that comes with Xcode for developing
interfaces.

To see it in action, in your side bar click the resources folder and click on the
ViewController.xib file.

The xib file is an interface file which is called a “nib file”. Once you double
click on the nib file it will automatically open the interface builder.

You will see the following on your screen…

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


The Interface builder has three main parts, namely -

1. Component Window

This shows the components of the interface. In our example we have…

The File’s Owner, First Responder and View, explained in a nutshell…

At this point of time you can consider these element as components by which
the interface is created and rendered on a device. The File owner is the master
class and the interface we creates belong to the File Owner. The First
Responder is responsible of responding to user inputs done at the interface. We
will deal with them in detail in our later sections. The View is the actual
interface that will be visible to the user.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


2. Library

The library is the collection of interface elements like Label, TextBox and
even view controllers. You can create great applications just by using these
standard components.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


3. Inspector

The inspector is the other major component of the interface builder. It


allows the developer to change various attributes of the interface object.

Using the Inspector we can change the following attributes -

View Attribute

Connection Attribute

Size attribute

Identity attribute.

If you want to have a look at these attributes, select the Inspector from the
Drop down menu and the window will appear in your screen.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Then, select View and the Inspector window will show different attributes
for each tab as listed above.

We will learn to use this a little later. We will first complete our application
which will print “Hello World” on the window.

Completing the Application

Open the library from the Xcode menu.

Go to the element label and drag it to the view window which is currently
gray in color.

You will see the following ...

Once your label is present on the view, you can clearly see the word “Label”
written on the view.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Moving forward, our task is to now convert this label to “Hello World”.

And… that is done very easily!

Simply double click on label and you can edit it to whatever you want.

Alternatively you can select the label and open up the Inspector. In view
attribute, that is first tab itself, change the text from label to Hello World.

Save the nib file and close the nib file by closing the component window.

So, now that we are done, we want to execute the first program we wrote!

In your Xcode top bar, click “Build and Run” and if everything is proper, you
will see the emulator appear and display the text… “Hello World” on the
screen, just as shown in the figure below…

Wasn’t that hard, was it ?

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Lets Move on to our Next Exercise

As we have now successfully created our first Application we will try to extend
this application and will try and add a user event to it.

To do this, we will have to augment the code created by Xcode.

What we want to do is to insert a button in the interface which can be clicked


by the user, and we should be able to change the message, as per the click.

We will start by creating an IBOutlet for the label which we want to change
and an IBAction to interpret the user action.

Make the following changes to Hello_WorldViewController.h

#import <UIKit/UIKit.h>

@interface Hello_WorldViewController : UIViewController {


IBOutlet UILabel *label;

@property (nonatomic, retain) IBOutlet UILabel *label;

-(IBAction)buttonPressed;

@end

The code above creates an Outlet of class UILabel to store the label object
which has been defined as *label.

We then make this object a property to automatically use getter and setter
functions later.

We then create a -(IBAction) buttonPressed trigger which will be called


when user presses the button element on the screen.

We now move on to the Interface builder, to create the necessary interface.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Double click the view controller nib file to open the interface builder.

Open the library and drag a round rectangle button from the library to get
the following view…

Click on the button and change the name to switch.

Now, we will associate this label with our UILabel object.

Control drag from the File Owner to the Label which is now written as “Hello
World” and from the pop up that appears select “label”. “label” was the
object we created in our code.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Refer to the two images below -

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Once our IBOutlet for label is set we will move to add the IBAction to
button.

To connect the IBAction we will select the button and open up the Inspector.

Go to the connection attributes and drag “Touch up inside” to the File


Owner.

Select the action “buttonPressed” from the pop up.

If the connection is successfully joined your Connection Inspector should look


like the following…

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Once this is done save your nib file and move on to the Xcode.

Now, open the Hello_WorldViewController.m file and add the following


code…

#import "Hello_WorldViewController.h"

@implementation Hello_WorldViewController
@synthesize label;

-(IBAction)buttonPressed{

if([label.text isEqualToString:@"World Hello"])


label.text = @"Hello World";
else
label.text = @"World Hello";

}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.


}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)dealloc {
[label release];
[super dealloc];
}

@end

We start by synthesizing the label object.

In the IBAction method we apply a simple conditional to check the current


string and then change the string based on the current stage.

This completes our Application which displays hello world and then changes
itself based on the user command.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


The output should look like this …

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


This concludes our introductory tutorial for iPhone Programming!
We hope you enjoyed it!

You may download the source code for the above project from the following
link - http://edumobile.org/downloads/Sample.zip

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Bonus Chapter on iPad Development

Jumping from iPhone to iPad Development

You must take advantage of the iPad launch and the benefits you can gain from
it. For this, you should definitely make your iPhone App compatible with iPad
also. The iPad went on sale in April 2010 in the market, and Apple created a
new section in iTunes that lists new iPad Apps or enhanced iPhone Apps that
are compatible with iPad.

All iPad users who have already downloaded your free or paid App to their
iPhone or iPod Touch will be able to download your iPhone App – only if you
have updated your binary submission to the App store to make your iPhone App
compatible with iPad. If you do not update and create the separate binaries,
then you are potentially losing out.

Using the new SDK you will be able to create a single binary which will install
one version of your app when used on the iPhone or iPod Touch and a different
binary when installed on an iPad. iPad development is an extension of iPhone
development and you must first learn iPhone programming, before you move on
to learning the new extended functions and features specially made for the
iPad. Some of the ways the iPad differs from the iPhone are…

Rotation Orientation Support –

Supporting rotation is a must on the iPad. This is because the iPad does not
have a normal way in which it will be held unlike the iPhone, which is normally
held vertically (portrait view). With the iPad the user can be comfortable with
both the vertical or horizontal (landscape) orientation. This means that your
iPad App has to support both orientations – that is, it must be able to rotate
and appear properly in both views.

View Controller -

All iPhone Apps which currently use UINavigator to switch to another view
showing details of something selected in a list, can now take advantage of the
new detailed view controller. This functionality will now provide simultaneous
viewing of the list and the detailed view – when in landscape orientation, or a
full-screen viewing of the details view with the list available in a popover view
– when in portrait orientation. All of the Apps will have to been rewritten to
use these new features and users will expect them of your applications as well.
You should use the UIKit functionality to build this into your App.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Popover Views –

Popover views are not supported in the iPhone, but can be used to create
modal dialogs, modeless dialogs, and menus in the iPad. Hence, all Apps which
use the master/detail view, will automatically convert the master list to a
popover menu when the iPad is placed in the Landscape orientation. You can
use this same popover technology to create menus, such as shown in Pages and
modeless dialogs. An example would be the color picker shown in the Brushes
App, or creating D-pad controls. These popover views can easily be closed by
the user by tapping on any region outside the popover window boundary.
Hence, while designing, make sure you leave some areas on the sides where
the user can touch the screen to dismiss the popover window. Design cleverly
to see where you can replace entire views with Popovers. This will greatly
simplify your apps on the iPad and the speed and ease with which users can
navigate quickly. Don note that since the iPhone and iPad Touch do not support
Popovers, you will need to create and use a custom view for them – should you
use Popovers in your iPad App.

Tabs -

Tabs can appear on the top or at the bottom of the screen on the iPad. This
gives you the ability to provide more traditional tabs on the top of the UX
rather than just at the bottom. You can thus also put tabs in the top of your
Popover views.

TableView -

TableView controls can now have multiple columns. Therefore, try to eliminate
custom controls or provide an enhanced UX to your users.

More Finger Gestures -

The limited screen size of the iPhone and iPad resulted in limitations in the
possible touch screen finger gestures. With the iPad and its bigger screen, a
whole new set of gestures are possible. There is plenty of space for long-touch
and also drag gestures and multi-finger controls ( the 3-finger twist gesture ).
You can see Steve Jobs doing this in the Developer Keynote Speech.

Also, since the iPad screen is large, Apple has built in a functionality that
supports multiple users touching different parts of the screen at the same
time. For example 2 people can play a game of hockey-puck with each other.
The iPad screen is hence large enough to allow different simultaneous gestures

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


in different parts of the screen so that each user can have their own virtual
control surface area.

Multimedia -

If you create video content areas, you do not have to display the video across
the entire screen, and you can restrict video to only a small portion or area of
the screen. This functionality can be used to combine the user experience with
multiple multimedia functionality.

The iPad supports mounting a shared file directory by connecting the iPad via
USB to a PC or Mac. This means you can easily share data files between your
devices if required by the App.

The iPad also supports wireless headsets and microphone, thus allowing total
hands-free voice-driven control of Apps.

The iPad has an optional “video out cable” – that you can use to project the
screen in full or part. This is fantastic for making presentations.

Using CoreGraphics, all Apps will now be able to generate PDF content. This
will allow you to generate reports in PDF should you App require this.

Compass and Location -

The Compass and Location / GPS functionality is only available in the higher
models of the iPad that support 3G. While developing you should make sure to
check for compatibility so that you can enable or disable the feature, as
appropriate.

Text Input and Keyboards –

Each text input field (using the TextView function), will support spell checking
and auto-completion by default – just as in the iPhone. You can define if you
want to auto-enable or disable this functionality.

You can also implement multiple custom virtual keyboard layouts within a
single App, thereby displaying different types of custom keyboard inputs like
Scientific keys, I.P. address keys etc. for TextView controls as needed.

Bluetooth connected keyboards are supported out-of-the-box. No need to


configure anything. Many users will probably selectively connect third party

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


keyboards to their iPad. Your App can be developed to support such alternate
text-input capability.

Screen Size Disparity -

Avoid undesirable uneven image stretching of your App when users change the
orientation of the iPad. The iPad is 1024 pixels in the tallest dimension and 768
pixels in the shortest dimension. These proportions are not the same as with
the iPhone or iPod Touch – and differ slightly. At the tall end the screen is
2.13x the size of the iPhone or iPod Touch. At the short end the size is 2.4x the
size of the iPhone or iPod Touch. Therefore, this slight disparity in proportions
will cause your view to stretch unevenly if you display it in full screen on the
iPad. You will therefore need to customize this view, if required for the iPad,
in order to avoid any uneven full screen resizing.

Execute Hello World Program on the iPad

This is the “HelloWorld” example, i am going to run this application in the


iPad. For the iPad application , required “iPhone SDK 3.2″ , so first install the
iPhoneSDK 3.2 . There have so many way to display the HelloWorld in the iPad,
but i’ll show you “HelloWorld” example using Interface Builder and writing
little code.This is the very simple application. So let see how it will be worked.

Step 1: Open the Xcode and create a new Xcode project usingView base
application template. Give the application name “Button Fun iPad”.

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


Step 2: Xcode automatically creates the directory structure and adds essential
frameworks to it. You can explore the directory structure to check out the
content of the directory.

Step 3: xpand classes and notice Interface Builder created


the Button_Fun_iPadViewController class for you. Expand Resources and notice
the template generated a separate nib, Button_Fun_iPadViewController.xib,
for the “Button Fun iPad”.

Step 4: In the Button_Fun_iPadViewController.h file, we have added UILabel


for display the text and added IBAction buttonPressed: so make the following
changes in the file.

#import <UIKit/UIKit.h>

@interface Button_Fun_iPadViewController : UIViewController {


IBOutlet UILabel *statusText;
}
@property (retain, nonatomic) UILabel *statusText;

-(IBAction)buttonPressed:(id)sender;

Step 5: After changing in the Button_Fun_iPadViewController.h, double click


the Button_Fun_iPadViewController.xib file open it to the Interface Builder.

a) Open the View window, first drag the label from the library and place it to
the view window and select the label and bring up Attribute Inspector and
delete the text.

b) Next drag a Round Rect from the library and place it to the view window.
double click the Round Rect and give the name “ClickMe”.

c) Now connect the File’s Owner icon to the View icon and select view.
d) Connect File’s Owner icon to label and select ”statusText”.

e) Select the Round Rect from the view window and bring up connection
Inspector.Drag from the TouchUpInside to the File’s Owner icon and select
buttonPressed: action. Now save the Button_Fun_iPadViewController.xib file,
close it and go back to the Xcode.

Step 6: Open the Button_Fun_iPadViewController.m file and make the


following changes in the file:

-(IBAction)buttonPressed:(id)sender
{
NSString *newText = [[NSString alloc] initWithFormat:
@" Hello World!!!"];
statusText.text = newText;
[newText release];
}

Step 7: Now compile and run the application in the Simulator.

You can download the SourceCode from here Button Fun iPad

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved


So,,, What Next ?

This was a small step in our journey towards getting started with iPhone
development. If you are interested in learning iPhone and iPad Development,
we suggest you sign up for our complete 12 Week iPhone Programming
Course at the link below. It comes with a full money back guarantee, so there
is no risk at all.

You will be assigned your own personal one-on-one tutor, whom you may
consult any time with questions and problems you face.

The course is delivered over a period of 12 weeks via Online Video that you
may download and view at your convenience, along with material and Weekly
Worksheets.

You will also get access to our private forum where you can meet other
fellow iPhone developers.

Click Here To Learn More About The iPhone Course and To Enroll

Affiliates Join Our High Paying Affiliate Program and Make Tons Of Money!

Interested in promoting our Courses and making money?

Get instant $25 bonus for signing up!

Click Here to sign up for our Affiliate Program

Copyright © 2009 – 2010 EDUmobile.ORG All Rights Reserved

You might also like