UIViewController viewWillAppear not called when adding as subView

前端 未结 8 1400
野性不改
野性不改 2020-12-14 06:43

I have a UIViewController that I am loading from inside another view controller and then adding its view to a UIScrollView.

self.st         


        
8条回答
  •  粉色の甜心
    2020-12-14 07:20

    You should add statisticsController as a child view controller of the controller whose view you're adding it to.

    self.statisticsController = [self.storyboard instantiateViewControllerWithIdentifier:@"StatisticsViewController"];
    self.statisticsController.match = self.match;
    
    [self.scrollView addSubview:self.statisticsController.view];
    [self addChildViewController:self.statisticsController];
    [self.statisticsController didMoveToParentViewController:self];
    

    I'm not sure this will make viewDidAppear get called, but you can override didMoveToParentViewController: in the child controller, and that will be called, so you can put any code that you would have put in viewDidAppear in there.

提交回复
热议问题