Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CylonGlitch

macrumors 68030
Original poster
Jul 7, 2009
2,958
268
Nashville
This is driving me nuts, because I know I had it working one time and then changed it to try something else and now can't go back to the way I had it.

Here is what I have, I'll try to keep it simple. I have one XIB with three different views. One is the main view, the other two are "info" panels that have that data laid out to look good either in Portrait or Landscape. There is a button on the main to bring you to the info page. And of course a back button on the info pages.

In the Main.h I have
Code:
@interface MainController : UIViewController
{
    UIView *InfoLand;
    UIView *InfoPort;
    Boolean Landscape;
    Boolean inInfo;
}
I setup everything upon initialization.

I have the button press event :
Code:
- (IBAction)pbInfo:(id)sender {
{
    if (Landscape)
        [[self view] addSubview:InfoLand];
    else
        [[self view] addSubview:InfoPort];
    inInfo = true;
}
I have the didRotate event trapped
Code:
- (void) didRotate:(NSNotification *)notification {
    if (Landscape) 
    {
        [InfoPort removeFromSuperview];   // ** UPDATE 2
        [[self view] addSubview:InfoLand];
    }
    else
    {
        [InfoLand removeFromSuperview];   // ** UPDATE 2
        [[self view] addSubview:InfoPort];
    }
}

- (IBAction)pbInfoBack:(id)sender {
    if (Landscape)
    {
        [InfoPort removeFromSuperview];  // ** UPDATE 2
        [InfoLand removeFromSuperview];
    }
    else
    {
        [InfoLand removeFromSuperview]; // ** UPDATE 2
        [InfoPort removeFromSuperview];
    }
}

I get the impression I'm doing something fundamentally wrong, because it keeps adding sub views. Everything looks like it is working, but the back button displays a garbled view, of whatever was last displayed.

I did make it, at one time, to add the two sub when the info button is clicked and then bring the correct sub view to the front. BUT when I do that the landscape view is only displayed in the upper half of the screen. I think because it is added when not in landscape mode?

Anyone have any idea what I'm doing wrong? I'd like to get it all working asap. :( I've been dragging this app along long enough.

Update, Additional Information
I launch the app, then while in portrait mode, I touch Info. If I touch the Back button while in portrait it goes back to the main screen. Perfect. But if I start in portrait to get to the Info screen, then Rotate and touch Back, it tries to go back to the Info Portrait not the Main page (that does work correctly in both modes).

Same is true if I rotate the main to landscape first. Then go to the info, everything looks right, I'm on the info landscape view. But if I rotate to portrait and then hit back it tries to go back to the landscape info view. :(

UPDATE2
See the code added for UPDATE2. This makes everything work the way I want it to.... ONCE. This is really odd. The first time everything works perfectly, exactly as I want it to. But when I touch Info for the second time, the views are clipped. The Portrait view is trying to be displayed in landscape mode and vice versa. Sounds like I just need to reset the subView boundaries?

I know it's something stupid, just not sure what yet. :D

Thanks for any help in advance.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.