Add a smaller subView with new origin
Posted
by ReachWest
on Stack Overflow
See other posts from Stack Overflow
or by ReachWest
Published on 2010-04-26T22:37:00Z
Indexed on
2010/04/26
22:53 UTC
Read the original article
Hit count: 157
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.
© Stack Overflow or respective owner