gpt4 book ai didi

ios - 将子 Controller 添加到 TableView 单元格时不会调用 viewWillAppear

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:07 24 4
gpt4 key购买 nike

当我将 subview Controller 添加到 TableView 单元格时,似乎没有调用 subview Controller 的 viewWillAppear,只有 viewDidAppear

TableView Controller 方法:

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
}

ViewController类方法:

- (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);
}];
}

知道为什么会这样吗?

最佳答案

- (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];

关于ios - 将子 Controller 添加到 TableView 单元格时不会调用 viewWillAppear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29710371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com