 |
 |
|
 |
06-17-2009, 02:26 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 17
|
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.
|
|
|
06-17-2009, 02:40 PM
|
#2 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
try
Code:
[self.view removeFromSuperview];
That's what I do in my app and it works.
|
|
|
06-17-2009, 03:23 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 17
|
Quote:
Originally Posted by jsd
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.
|
|
|
06-17-2009, 04:36 PM
|
#4 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
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.
|
|
|
06-17-2009, 05:17 PM
|
#5 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 17
|
Quote:
Originally Posted by jsd
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.
|
|
|
06-17-2009, 05:48 PM
|
#6 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
try this:
Code:
[self.view.superview addSubview:settingsControllerview.view];
[self.view removeFromSuperview];
|
|
|
06-17-2009, 10:12 PM
|
#7 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 17
|
Quote:
Originally Posted by jsd
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
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 496 |
| 59 members and 437 guests |
| alexcrick209, atsd, AXP, bbc z, bensj, BostonMerlin, brianmethod, cakeisalie, cornishGeeza, CunningCat, davek, dbarrett, dda, deden, DevJustin, Dorald, embedded, ggalante, gonk, harrytheshark, healthyutech, iPhoneDevelopment, IphoneSdk, Jeremy1026, jharrah, kjelleinar, krowczyk, Link, markbuchanan, MarkC, masc2279, mebarron, naomipunkclan, nibby, Noise, pbcbvba, pieter78, raheel, Sckah, Sesa, SimonK, sjdev, soulless, StefanL, Tambourin, the1nz4ne, treazer, tturk, Type25, virvalid, Vivek Nirkhe, Vonswanko, wassupdoc, winklllll, x2on |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,507
Threads: 35,791
Posts: 156,790
Top Poster: smasher (2,449)
|
| Welcome to our newest member, soulless |
|