Ser*_*nko 2 iphone uiviewcontroller ios
当我将子视图控制器添加到表视图单元格时,它看起来像子视图控制器的viewWillAppear没有被调用,只有viewDidAppear.
表视图控制器方法:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("ShopInfoTableViewCell", forIndexPath: indexPath) as! ShopInfoTableViewCell
    self.addChildViewController(self.shopInfoViewController, toView: cell.containerView)
    return cell
}
查看控制器类别方法:
- (void)addChildViewController:(UIViewController *)childController toView:(UIView *)view
{
    [self addChildViewController:childController];
    [view addSubview:childController.view];
    [childController didMoveToParentViewController:self];
    [childController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top);
        make.bottom.equalTo(view.mas_bottom);
        make.left.equalTo(view.mas_left);
        make.right.equalTo(view.mas_right);
    }];
}
任何想法为什么会发生?
ada*_*ali 22
- (void)addChildViewController:(UIViewController *)childController toView:(UIView *)view
{
    [self addChildViewController:childController];
    //add this
    [childController beginAppearanceTransition:YES animated:YES];
    [view addSubview:childController.view];
    [childController endAppearanceTransition];
    [childController didMoveToParentViewController:self];
    [childController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top);
        make.bottom.equalTo(view.mas_bottom);
        make.left.equalTo(view.mas_left);
        make.right.equalTo(view.mas_right);
    }];
}
同样,当你想要消失时,你应该调用它
    [childController beginAppearanceTransition:NO animated:YES];
    [childController.view removeFromSuperview];
    [childController endAppearanceTransition];
| 归档时间: | 
 | 
| 查看次数: | 5138 次 | 
| 最近记录: |