I have a NavigationController and I want to make a View that animates itself from the top of the screen and sits above navigationBar. I'm initialising viewcontroller from a xib and it works perfectly when I add it as [self.view addSubview:myView];
, but it sits below navigation bar. When I try to add it as [self.navigationController.view addSubview:myView];
it places it on top of navigationBar as intended but view doesn't display any of it's subviews placed in xib. I can't see why this is happening, have been trying to solve this for hours.
UPDATE My custom view from a xib is paired with custom ViewController class and I added this code in it :
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"!!! %i", [self.view.subviews count]);
}
if I add myView to self.view it prints 1 (there's actually 1 subview), but when I add it as self.navigationController.view -viewDidAppear
is not even called. But it does appear on the screen with no subviews. Now I'm even more confused.
Turns out I'm an idiot. It's a really simple scope problem. I was instantiating a local variable of my VC inside the method, and of course it was released at the end. As soon as I assigned my VC to a global variable all started to work like a charm. Easy as that.