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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 06-17-2009, 02:26 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 28
Default removing (or identifying) the default view

I'm having trouble removing the default view in a iPhone app. I started with a view based app and want to have button that simply changes to a settings page. I set up the main view with a button called "settings". I set up the settings view. I was able to hook the settings up to its own controller and then in the controller for the main page add this action. This works, but puts the new view behind the start view, so I can see the settings button on the settings page.

Quote:
-(IBAction) startSettings: (id)sender { SettingsViewController *settingsControllerview = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil]; [self.view insertSubview:settingsControllerview.view atIndex:0]; }
So I figured I just need to remove the first view. I thought this would work:

Quote:
[viewController.view removeFromSuperview];
Because that's how the delegate originally added it
Quote:
[window addSubview:viewController.view]; [window makeKeyAndVisible];
But no such luck. So I'm really confused. Obviously, I've got the wrong name for the existing view, but how do I discover what the correct name is?

Any guidance would be greatly appreciated, I've been tearing my hair out for three hours on this.
mbarron is offline   Reply With Quote
Old 06-17-2009, 02:40 PM   #2 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

try
Code:
[self.view removeFromSuperview];
That's what I do in my app and it works.
jsd is offline   Reply With Quote
Old 06-17-2009, 03:23 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 28
Default

Quote:
Originally Posted by jsd View Post
try
Code:
[self.view removeFromSuperview];
That's what I do in my app and it works.
Thanks, but when I change my code to the following:

Code:
-(IBAction) startSettings:(id)sender {
	[self.view removeFromSuperview];
	SettingsViewController *settingsControllerview = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil];
	[self.view insertSubview:settingsControllerview.view atIndex:0];
	
}
I get a completely blank screen. I'm thinking that I just destroyed the view that I'm trying to insert settingsControllerView into.any other suggestions?

{added} in my previous button I seemed to be hiding the view container, but not the buttons within. That is, the background of start and settings are different and change, but the buttons from start remain on the screen. Hope that helps someone point me in the right direction.

Last edited by mbarron; 06-17-2009 at 03:49 PM.
mbarron is offline   Reply With Quote
Old 06-17-2009, 04:36 PM   #4 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

You've got it in the wrong order - think about it... If you remove the view first, then inserting something into it later once it's already off the screen isn't going to work.

Add the second view, then remove the first.
jsd is offline   Reply With Quote
Old 06-17-2009, 05:17 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 28
Default

Quote:
Originally Posted by jsd View Post
You've got it in the wrong order - think about it... If you remove the view first, then inserting something into it later once it's already off the screen isn't going to work.

Add the second view, then remove the first.
Sorry, I know I'm being really dense here, but this still doesn't work. I understand what you're saying: when I remove the view first, I have nothing to put the view into. But if I move it last like this:
Code:
-(IBAction) startSettings:(id)sender {

	SettingsViewController *settingsControllerview = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil];
	[self.view insertSubview:settingsControllerview.view atIndex:0];
	[self.view removeFromSuperview];
	
}
I'm just now removing the view that I just inserted my subview into. It seems like I either need a way to identify my previous subview (the part of self.view that I want to remove) or just create a whole new blank view and insert my new subview into it. But god help me if I've been able to figure it out. Again, I'd appreciate any help you can provide.
mbarron is offline   Reply With Quote
Old 06-17-2009, 05:48 PM   #6 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

try this:
Code:
[self.view.superview addSubview:settingsControllerview.view];
[self.view removeFromSuperview];
jsd is offline   Reply With Quote
Old 06-17-2009, 10:12 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 28
Default

Quote:
Originally Posted by jsd View Post
try this:
Code:
[self.view.superview addSubview:settingsControllerview.view];
[self.view removeFromSuperview];
That worked! I'm going to name my first baby jsd. Ok, I'm not, but I'm very greatful! It's embarrassing how long this took me, but at least I think I understand (a little) what's going on.

-Martin
mbarron is offline   Reply With Quote
Reply

Bookmarks

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: 931
12 members and 919 guests
7twenty7, astalavista, davidcoderlab, donlucacorleone, JuliaHarris, leticiatroutman, marWIN77, narutov2, nikhil, Stokestack, TheWebWizz, watermelonvodka
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,479
Threads: 89,092
Posts: 380,125
Top Poster: BrianSlick (7,091)
Welcome to our newest member, JuliaHarris
Powered by vBadvanced CMPS v3.1.0

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