How to Use Navigation in iPhone and iPad

Introduction

In this article we create an Empty view application. In this we create a view using the uiviewcontroller class. To create the uiviewcontroller class we do the following.

Select the appdelegate.m class and right-click on it ->choose new file ->select objective C class ->click on next ->by default the class name is ViewController. When you choose subclass UIViewController, change the name to whatever you want; if you want to use xib then you mark on it -> click on next -> select the location where you import the view controller class in the project.

To navigate one view to another here I use two the UIViewController class. First class name first view controller and Second class name second view controller. In this article I use one button and one label in the First view and a single label is used in the second view using xib. When we click on the first button "click!" it navigates from one view to another. 

Step 1

Open XCode by double-clickiing on it.

Select-xcode-in-iphone.jpg

Step 2

Create a New XCode Project by clicking on it.

create-project-in-iphone.jpg

Step 3

Now select an Empty View Application and click on Next.

Empty-Application-in-iPhone.jpg

Step 4

Now Give your Product a Name. Here I use Nevigation and Company Identifier Mcn Solutions and Click on Next.

Project-name-in-iPhone.png

Step 5

Select the location where you want to save your project then click on Create.

save-project-location-in-iphone.jpg

Step 6

Now you can see in the XCode Window two Objective C classes that were generated by XCode; they are:

1.Appdelegate.h
2.AppDelegate.m

welcome-window-in-iPhone.png

Now we add two UIViewControllers, as in the following.

Step 7  

Select the appdelegate.m class and right-click on it; see:

 choose-new-file-in-iPhone.png

Choose New File..

Step 8

Select Subclass of UIViewController from drop down list and give the class name. Here I use the class name First view controller and click on the checkbox with xib user interface. For using a label and button from xib.

first-class-name-in-iPhone.png

Click on next.

Step 9

Now click on create, to import a class to the project; see:

select-class-target-in-iPhone.png

Repeat the same steps to add a second view controller class.

second-class-name-in-iPhone.png

Step 10

After that we add code for navigation and linking.

select-button-action-touch-up-inside-in-iPhone.png

Step 11

Now select which Platform you want to see the output for.

run-in-iPhone.png

Output

Output 1 for iPhone:

output1-in-iPhone.png.jpg

Output 2 for iPhone:

output2-in-iPhone.png.jpg

Output 1 for iPad:

output1-in-iPad.png.jpg

Output 2 for iPad:

 output2-in-iPad.png.jpg


Similar Articles