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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-17-2009, 07:38 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 8
iamstuck is on a distinguished road
Default Changing views

Hi there,

Thanks in advance for any help. I've searched everywhere for an answer to this and simply can't figure it out. I'm very new to all this so I'm sure this is probably really basic and I'm just missing something obvious.

Basically, I'm building a multi-view application, with an initial view containing 2 buttons. Tapping either button should load up a new view, but I can't get this to work at all.

I have several classes:

My_ApplicationAppDelegate
SwitchViewController
SplashScreenViewController
ScreenOneViewController
ScreenTwoViewController

SwitchViewController loads the SplashScreenViewController class.

SplashScreenViewController is associated with a NIB file containing the 2 buttons. Clicking button 1 should load screen 1 and clicking button 2 should load screen 2.

SplashScreenViewController.m contains 2 functions (one for each button press), which in turn call the functions to do the actual view switching, located in SwitchViewController.

The problem I have is that I can get these functions to run fine (if I printf I can see the output in the console) but I can't get them to actually remove the splash screen view and replace it with screen one or screen two.

The idea of having an overall SwitchViewController class to handle all my screen changes seemed sensible (maybe I'm wrong though), so I'm guessing it's just that I'm not removing the right view maybe? But I get no error messages.

My code for the functions called by the button clicks and the subsequent functions they call are below. I've double checked all the nibs have all the proper connections etc...

Button tap code located in SplashScreenController.m

Code:
- (IBAction)postButtonPressed:(id)sender {

SwitchViewController *switchViewController = [[SwitchViewController alloc] init];
// call function in the SwitchViewController class
[switchViewController switchToScreenOneView];
[SwitchViewController release];

}
Code located in SwitchViewController.m

Code:
#import "SwitchViewController.h"
#import "SplashScreenViewController.h"
#import "ScreenOneViewController.h"
#import "ScreenTwoViewController.h"

@implementation SwitchViewController
@synthesize splashScreenViewController;
@synthesize screenOneViewController;
@synthesize screenTwoViewController;

- (void) switchToScreenOneView {
// remove the current view
[splashScreenViewController.view removeFromSuperview];

// load the new view
ScreenOneViewController *screenOneController = [[ScreenOneViewController alloc] initWithNibName:@"ScreenOneView" bundle:nil];
self.screenOneViewController = screenOneController;
[self.view insertSubView:screenOneViewController.view atIndex:0];
[screenOneController release];

}
Thanks again for any help anyone can offer. It would be greatly appreciated.

All the best,
Ian

Last edited by iamstuck; 08-17-2009 at 07:41 AM. Reason: Typo
iamstuck is offline   Reply With Quote
Old 08-17-2009, 11:22 AM   #2 (permalink)
Humbled Student
 
Dutch's Avatar
 
Join Date: Apr 2009
Location: Long Island, NY
Age: 32
Posts: 883
Dutch will become famous soon enough
Send a message via AIM to Dutch
Default

I * think * I see what is happening here... You are removing the Spalsh screen (presumably from [yourDelegate window]) and you are setting the SwitchViewController's view - but you are never adding the ViewController's view to the [yourDelegate window]...

Just for giggles... try adding the second 2 lines....

Code:
[switchViewController switchToScreenOneView];

YourAppDelegate *mainDelegate  = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[[mainDelegate window] addSubView:switchViewController.view];
Obviously, "YourAppDelegate" would be replaced (in both places) with the class name of your app delegate.

Last edited by Dutch; 08-17-2009 at 11:27 AM.
Dutch is offline   Reply With Quote
Old 08-18-2009, 03:13 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Santa Clara, CA
Posts: 10
Dachmt is on a distinguished road
Default

Hi,

I had a same problem with managing multiple views. My application has a splashscreen for logging, then it should display another view (a UITabBarController, not UIView) if the connection succeeds.

I found an interested video that explain how to manage different views iPhone Tutorial - Multiple XIB files on Vimeo. I prefer his way to manage views than the way you are using (even if most of website show how to manage views like you did).

Hope it can help.
Dachmt is offline   Reply With Quote
Reply

Bookmarks

Tags
change views, subview, superview, view

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
» Online Users: 315
12 members and 303 guests
chiataytuday, coolman, givensur, glenn_sayers, guusleijsten, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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