ViewDidAppear does not receive a call

In my main UIViewController, I add a home screen view controller as subviews:

   UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vc];
        controller.navigationBarHidden = YES;
        controller.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        [self addChildViewController:controller];
        [self.view insertSubview:controller.view atIndex:0];
        [controller didMoveToParentViewController:self];    

The problem is that viewDidAppear and viewWillAppear are called only once, just like viewDidLoad. Why is this? How do I do this job?

Mostly inside vc, I get neither viewDidAppear nor viewWillAppear.

I also just tried adding a UIViewController without a navigation controller, and it still doesn't work:

vc.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        [self addChildViewController:vc];
        [self.view insertSubview:vc.view atIndex:0];
        [vc didMoveToParentViewController:self];    
+7
source share
7 answers

Representation of view controllers using currentModalViewController or segues or pushViewController should fix it.

, - , . - :

[self addChildViewController:controller];
BOOL animated = NO;
[controller viewWillAppear:animated];
[self.view insertSubview:controller.view atIndex:0];
[controller viewDidAppear:animated];
[controller didMoveToParentViewController:self];   
-7

viewDidAppear , viewWillAppear.

-(void)viewWillAppear:(BOOL)animated {
    [super viewdidAppear:animated]; // this prevented my viewDidAppear method to be called
}
+20

, , - ( , ):

- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
{
    return NO;
}

, :

- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
{
    return YES;
}

child viewWillAppear (, automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers), .

Update:

, , , , (B) ( ), (C), B C , , viewWillAppear viewDidAppear B. , ( , , , , , ).

, .

+13

@Rob Swift 4 ( , childViewController UITabBarController)

override var shouldAutomaticallyForwardAppearanceMethods: Bool {
    return true
}
+6

retain property, , childViewControllers array.

,

[self addChildViewController: childViewController];

UIKit ,

strong weak

+1

, UITabBarController (selectedIndex = x), . , : , , selectedIndex. viewWillAppear/viewDidAppear .

0

13.0 viewDidAppear.

Objective-c all .

ViewDidAppear... IOS (12 ).

@implementation MasterViewController

//....some

  • (BOOL) shouldAutomaticsForwardAppearanceMethods {return YES; }

// ... some methods

@end

0
source

All Articles