AlternativeViews In iPhone

In this application we will how to  implement alternate or distinguishing view controllers for each particular device orientation.

Step 1: Create a Window base application using template. Give the application name “Portrait Landscape”.

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: Now we’ll add Table view controller class to the project. Choose New file -> Select cocoa touch classes group and then select UIViewController subclass. Give the name LandscapeViewController.m, do it once more time and give the name PortraitViewController.m.

Step 4: In the AppDelegate.h file, we define UINavigationController. Make the following changes in the AppDelegate.h file .

 

 

 

Step 5: Make the following changes in the  AppDelegate.m file.

 

 

 

Step 6: Now we will add .xib file in the resource folder. Add -> New File -> User Interface  ->View XIB  and give the name PortraitViewController.xib, save it. Do it once more time and give the name LandscapeViewController.xib.

Step 7: In the PortraitViewController.h file we define landscapeViewController , so make the following changes in the file.

 

 

 

Step 8: Double click your PortraitViewController.xib file and open it to the Interface Builder. Drag label from the library and place it to the view window. Select it and bring up Attribute inspector change the text into Portrait . Connect the File’s Owner icon to the View icon. Save it and go back to the xcode.

Step 9: Make the following changes in the PortraitViewController.m file.

 

 

 

Step 10: Now double click your MainWindow.xib file and open it to the Interface Builder. Drag Navigation Controller from the library and place it to the mainwindow. Open the Navigation View Controller and change the title into Portrait to Landscape . Now select View Controller and bring up identity Inspector, change the class name into PortraitViewController. Save it and go back to the Xcode.

Step 11: In the LandscapeViewController.h file make the following changes.

 

 

 

Step 12: Double click the LandscapeViewController.xib open it to the Interface Builder. Select view window and bring up Size inspector, change the size width 480 and height 320. Now drag the label from the library and place it to the view window, select it and bring up attributes inspector change the text into Landscape. Connect the File’s Owner icon to the View icon. Save it and go back to the Xcode.

Step 13: Now change the LandscapeViewController.m file.

 

 

 

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

You can downloaded SourceCode from here Portrait Landscape 2Landscape

Leave a Comment:

1 comment
Mistunk says March 26, 2010

Can we have the source code ?

Reply
Add Your Reply