Try NSLog
in the viewWillAppear
method.
You only get the dimensions of the view at viewWillAppear
Question
I just don't get the setting of my view controller right. I have a ViewController implemented into another ViewController like this:
PARENT VIEWCONTROLLER:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self addTopTabBarController];
}
return self;
}
- (void)addTopTabBarController {
self.topTapController = [[TopBarViewController alloc] init];
[self addChildViewController:self.topTapController];
[self.topTapController didMoveToParentViewController:self];
[self.view addSubview:self.topTapController.view];
self.topTapController.view.frame = CGRectMake(0, 200, 320, 40);
}
CHILD VIEWCONTROLLER
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Setup toolbar an set frame
self.toolbar = [[UIToolbar alloc] init];
NSLog(@"%f", self.view.frame.size.height);
}
return self;
}
When I log the frame.size.height, I get 568.0 as return value. Why don't I get returned the 40 as being set in the parent ViewController before? Did I returned the wrong property?
Solution
Try NSLog
in the viewWillAppear
method.
You only get the dimensions of the view at viewWillAppear