How To ChangeView In The iPad

In this application we will see how to change view using button pressed. This is the very simple application. Let see how it will be worked.

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

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: We need to add three UIViewController class to the project. Choose New file -> Select cocoa touch classes group and then select UIViewController . Give the file names  “SwitchViewController”, “FirstViewController” and create corresponding .xib file, and create  another class ”SecondViewController ” and corresponding .xib file.

Step 4: We need to add images in the Resources folder. Give the name of the images “1.png”,”2.png”.

Step 5: In the AppDelegate.h file , we have added SwitchViewController class. So make the following changes in the file.

 

 

 

Step 6: Open the AppDelegate.m file and make the following changes:

 

 

 

Step 7: Now open the SwitchViewController.h file, we have added FirstViewController and SecondViewController class in the file and added one ChangeView method . Make the following changes in the file.

 

 

 

Step 8: Double click MainWindow.xib file and open it to the Interface Builder. First drag ViewController from the library and place it to the MainWindow.Select the ViewController icon from theMainWindow and bring up Identity inspector and change the class name into SwitchViewController. Open the SwitchViewController and drag the View from the library and place it,in the SwitchViewController view. Next drag Toolbar from the library and place it buttom portion of the view and drag Bar Button Item from the library and place it on the ToolBar . Change the Bar Button Item name into Switch Views. Connect the MultiViewiPadAppDelegate icon to the SwitchViewController icon and select switchViewController. Select the SwitchViewController icon from the MainWindow and bring up Connection Inspector, drag from the ChangeView to the Bar Button Item. You have done all the connection, so now save the SwitchViewController.xib file , close it and go back to the Xcode.

Step 9: Open the SwitchViewController.m file and make the following changes:

 

 

 

Step 10: Double click the FirstViewController.xib file and open it to the Interface Builder. First drag the image view from the library and place it to the view window, select the view and bring up Attribute Inspector, select the image “1.png”. Connect the File’s Owner icon to the View icon and select the view. Do the same for SecondViewController.xib file just select the image “2.png”. Now save the .xib file, close it and go back to the Xcode.

Step 11: Its all ready ,now compile and run the application in Simulator.

You can Download SourceCode from here MultiViewiPad

Leave a Comment:

3 comments
Smokin Joe says June 16, 2010

The SourceCode doesn’t work at all off the bat, and even after some troubleshooting I could maybe fix 10 or so parse errors.

If you’re at all interested in keeping this code working, let me know, I’d love to help out getting it to work.

I’m dying to just figure out a way to switch views on the ipad – I guess I shouldn’t be using the iphone navigation paradigm, but I can’t find any good examples of how to do it anywhere else.

Reply
Smokin Joe says June 16, 2010

Well shut my mouth, I have NO clue what I was doing wrong, or maybe I’m just posting in the complete wrong thread…

But I just re-downloaded it and it works perfectly.

Thanks for the effort and work man!

Reply
Pedro Rodrigues says March 4, 2011

Hi
How to switch between 5 (five) or more views ?
I tried create more, but without success.

Reply
Add Your Reply