views:

56

answers:

1

I can't get my head around this - I know it must be simple.. I'm starting to feel pretty stupid. I have two viewControllers. MainViewController.h/m and LevelsViewController.h/m

I want to add a subView from the LevelsViewController class and a view that is built in IB called levelsView. I am calling this from the MainViewController.m file. The levelsView is only 200x200 pixels and I want to offset it from the frame origin of the superView by x=140 pixels and y=50 pixels.

I have this working - the view displays, but I can't figure out how to offset it. It only shows up at the 0,0 superView frame origin. (The superView shows below it, which is what I want).

Here is the code I call in the method in the MainViewController.m that displays the levelsView.(I have commented out some of the things I have tried - but throws this error: error: request for member 'frame' in 'myLevelsView', which is of non-class type 'LevelsViewController*'

)

- (void) displayLevelsPage {

    if (self.theLevelsView == nil) // Does not yet exist - therefore create
    {
        LevelsViewController * myLevelsView = [[LevelsViewController alloc] initWithNibName:@"levelsView" bundle:[NSBundle mainBundle]];
        NSLog(@"NEW theLevelsView instance created!");
        CGRect frame2 = CGRectMake(140, 50, 200, 200);
        //myLevelsView.frame = frame2;
        self.theLevelsView = myLevelsView;
        [myLevelsView release];
    }

    [self.view addSubview: theLevelsView.view];
    NSLog(@"Levels View has been activated");
}

Any insight would be appreciated.

+2  A: 

myLevelsView doesn't have a frame but it does have a view and that has a frame, so your commented out line could be:

myLevelsView.view.frame = frame2;

But a viewcontroller should not have a viewcontroller as a subview. A viewcontroller is meant to control the entire view. Only 1 view controller can be controlling the screen at a time. Use a UIView (or any subclasses of UIView) for any subviews within the MainViewController.

progrmr
Thanks - that solved the problem. Yes - I was aware of the ViewController issue, but thought that by disabling all user interaction on the superView with setUserInteractionEnabled:NO, I could get away with it. Perhaps not the best strategy.
ReachWest