Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials > Tutorial Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-25-2010, 07:06 AM   #1 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default How To Switch View Controllers

Hi, i am going to teach you how to switch view controllers.

First Goto file New Project, and name it SwitchViews.

Secondly you need to program an IBAction in your .H file. It needs to look something like this:

Code:
- (IBAction)switchViews;
Once you have done that open Interface Builder and create a new Round Rect Button. Then hold down ctrl from the files owner to the button. Then a small menu should popup. Select switchViews, and touch up inside.

Next right click on the classes folder and add a new View Controller Subclass, and name it SecondView. Make sure you select it to come with a XIB interface.

Now go into the SwitchViewsViewController.M file.
First Import the viewController that you want to switch to. This goes above the @implementation SecondView

Code:
 #import "SecondView.h"
We now need to program the button.

Code:
- (IBAction)switchViews 
//Change secondView and replace it with you viewcontroller that you want to switch to.
{ 
	SecondView *second = [[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil] autorelease];
	// you can change flip horizontal to many different other transition styles.
	second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:second animated:YES];
}
Now we need to make a back button in the SecondView to let us go back to the original view.
So open up SecondView.h and make an IBAction called goBack.
Code:
- (IBAction)goBack;
Open up SecondView.m and we will program it. So open your .M file:
Code:
- (IBAction)goBack
{
[self dismissModalViewControllerAnimated:YES];
}
Finally open Interface Builder with the SecondView.xib
Add a Navigation Bar and a ToolBar Button.
Rename the ToolBar Button to Back and the click on Files Owner and drag the IBAction to the Back button, and select goBack.


Now that should work, Hope this Helps.

Last edited by iSDK; 12-09-2010 at 07:27 PM.
iSDK is offline   Reply With Quote
Old 10-01-2010, 10:54 AM   #2 (permalink)
Registered Member
 
Pilsner6910's Avatar
 
Join Date: Sep 2010
Location: Canada
Age: 43
Posts: 107
Pilsner6910 is on a distinguished road
Default hmm

ok yes im a total newb

for some reason im getting a "Incomplete implementation of class 'SwitchViewsViewController' warning, method definition for '-switchViews' not found.... in SwitchViewsViewController.m

so when i build and run then click "switch button" it crashes...hmmm

my new hobby certainly is interesting lol
Pilsner6910 is offline   Reply With Quote
Reply

Bookmarks

Tags
switchingviews, switchviews, view controller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,960
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0