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 04-14-2010, 02:31 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
bate5150 is on a distinguished road
Default View Controller Swapping Problem

Hi, I was wondering if someone could tell me what I'm doing wrong here. I'm making a simple application that I can use as a template for future projects that use nested view controllers. The code should work, or at least I thought. Here is the part of code that's causing my app to crash when I attempt to run it:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	
    [window makeKeyAndVisible];
	FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
	self.firstView = aView;
	
//The next line, where I add the subview, is what
//is making my app crash when I try to run it

        [window addSubview:firstView.view];
	[aView release];
	
	return YES;
}
The FirstViewController class has no instance variables, its .xib file just has a button linked to a function for switching between itself and the second controller. The two view controllers swap by calling a method from the delegate class that does a simple animation and replaces one view with the other.

The debugger just tells me that the app terminates due to an uncaught exception, but I don't know what I did wrong. If you need to see more of the code just ask. Help
bate5150 is offline   Reply With Quote
Old 04-14-2010, 03:53 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 110
Mike J is on a distinguished road
Default

Try this:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	
    [window makeKeyAndVisible];
	FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
		[self setfirstView:aView];
        [window addSubview:firstView.view];
	[aView release];
	
	return YES;
}



Quote:
Originally Posted by bate5150 View Post
Hi, I was wondering if someone could tell me what I'm doing wrong here. I'm making a simple application that I can use as a template for future projects that use nested view controllers. The code should work, or at least I thought. Here is the part of code that's causing my app to crash when I attempt to run it:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	
    [window makeKeyAndVisible];
	FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
	self.firstView = aView;
	
//The next line, where I add the subview, is what
//is making my app crash when I try to run it

        [window addSubview:firstView.view];
	[aView release];
	
	return YES;
}
The FirstViewController class has no instance variables, its .xib file just has a button linked to a function for switching between itself and the second controller. The two view controllers swap by calling a method from the delegate class that does a simple animation and replaces one view with the other.

The debugger just tells me that the app terminates due to an uncaught exception, but I don't know what I did wrong. If you need to see more of the code just ask. Help
Mike J is offline   Reply With Quote
Old 04-14-2010, 04:25 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
bate5150 is on a distinguished road
Default

Quote:
Originally Posted by Mike J View Post
Try this:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	
    [window makeKeyAndVisible];
	FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
		[self setfirstView:aView];
        [window addSubview:firstView.view];
	[aView release];
	
	return YES;
}
Thanks for the response.

I tried that but no dice, I'm at a loss because it really seems to me like it should work. I've followed the program step by step through almost everything and it just terminates here...
bate5150 is offline   Reply With Quote
Old 04-14-2010, 05:43 PM   #4 (permalink)
Registered Member
 
Innovation's Avatar
 
Join Date: Nov 2009
Location: Toronto
Posts: 38
Innovation is on a distinguished road
Default

In your NIB check to make sure it has it's view property set. If it doesn't have a view add one to the NIB, then right click on the file owner (should be FirstViewController) and set the view outlet to the added view. This is a usual suspect.

Quote:
Originally Posted by bate5150 View Post
Thanks for the response.

I tried that but no dice, I'm at a loss because it really seems to me like it should work. I've followed the program step by step through almost everything and it just terminates here...
Innovation is offline   Reply With Quote
Old 04-14-2010, 06:30 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
imsatasia is on a distinguished road
Default

Quote:
Originally Posted by bate5150 View Post
Thanks for the response.

I tried that but no dice, I'm at a loss because it really seems to me like it should work. I've followed the program step by step through almost everything and it just terminates here...
Try the following:

Code:
FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
	
[window addSubview:aView];
[aView release];
__________________
--
mySite
imsatasia is offline   Reply With Quote
Old 04-14-2010, 07:26 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
bate5150 is on a distinguished road
Default

Quote:
Originally Posted by Innovation View Post
In your NIB check to make sure it has its view property set. If it doesn't have a view add one to the NIB, then right click on the file owner (should be FirstViewController) and set the view outlet to the added view. This is a usual suspect.
I checked to make sure but the nib has a view and its outlet is set to the view. Also File's Owner is of the FirstViewController class so that's not the problem either.
bate5150 is offline   Reply With Quote
Old 04-14-2010, 07:29 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
bate5150 is on a distinguished road
Default

Quote:
Originally Posted by imsatasia View Post
Try the following:

Code:
FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
	
[window addSubview:aView];
[aView release];
This probably won't work, aView cannot be used as an argument for addSubview, it needs UIView and aView is from class FirstViewController.

I tried using aView.view but it also crashed when I tried this.
bate5150 is offline   Reply With Quote
Reply

Bookmarks

Tags
uiview, uiviewcontroller

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: 317
16 members and 301 guests
chemistry, Domele, Duncan C, Fstuff, givensur, heshiming, HowEver, iAppDeveloper, iphonedevshani, jbro, JoeRCruso, kapps11, newDev, SLIC, stanny, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,874
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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