Set Title on Navigation Bar in iPhone

Introduction

In this article we create an empty view application and use a uiviewcontroller class to navigate from one view to another. To set a title on the navigation bar we code in a correspondence view class in which we want to set the title.

Here I use two views; FirstViewController and SecondViewController and set the title on the navigation bar of the first view to "ROCKSTAR" or the navigation bar of the second view to "SACHIN".

Step 1

Open XCode by double-clicking 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 Empty View Application and click on Next.

Empty-Application-in-iPhone.jpg

Step 4

Now give your Product Name, Company Identifier and click on Next.

Project-name-in-iPhone.png

Step 5

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

save-project-location-in-iphone.jpg

Step 6

Now you will see in the XCode Window two Objective-C Classes were generated by XCode.

1. Appdelegate.h
2. AppDelegate.m

Now we add two UIViewControllers; for that we use Steps 7 to 9.

Step 7  

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

choose-new-file-in-iPhone.png

Choose New File..

Step 8

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

first-class-name-in-iPhone.png

Click on next

Step 9

Now click on create. For importing the class into the project:

select-class-target-in-iPhone.png

Repeat Steps 7 to 9 to add the second view controller class.

second-class-name-in-iPhone.png

Step 10

After that we code for navigation and linking.

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

Step 11

To set the title on the navigation bar we code:

code-of-set-title-on-nevigationbar-in-iPhone.png

Step 12

Now select which platform you want to see output for:

run-in-iPhone.png

Output

Output 1 in iPhone:

output1-in-iPhone.jpg

Output 2 in iPhone:

output2-in-iPhone.jpg


Similar Articles