为什么在将另一个ViewController作为FormSheet呈现时不调用viewWillAppear

时间:2022-12-05 14:59:45

I have 2 VC, A and B, when A present B as a FormSheet type, the method viewWillDisappear in A not called. So when I do something in B, and press back to A, the ViewWillAppear not called. So how to make the viewWillAppear in A called? I've seen somewhere, but I din't find the clearly answer.

我有2个VC,A和B,当A将B作为FormSheet类型时,方法viewWillDisappear在A中不被调用。因此,当我在B中执行某些操作并按回A时,未调用ViewWillAppear。那么如何在A中调用viewWillAppear呢?我在某个地方见过,但我找不到明确的答案。

In B I set:

在B我设置:

protocol CallBackViewWillAppearDelegate: class {
    func callBackViewWillAppear(controller: UserRightRoleTableViewController)
}

and delegate variable:

和委托变量:

weak var callBackViewWillAppearDelegate: CallBackViewWillAppearDelegate?

and in the back button:

并在后退按钮:

@IBAction func backToUserRightButtonAction(sender: AnyObject) {
        callBackViewWillAppearDelegate?.callBackViewWillAppear(self)
        dismissViewControllerAnimated(true, completion: nil)         
    }

In A I import the protocol and set the protocol function:

在A中我导入协议并设置协议功能:

func callBackViewWillAppear(controller: UserRightRoleTableViewController) {
        viewWillAppear(true)
    }

2 个解决方案

#1


0  

The method viewWillDisappear is not called for A controller because this stays on the view hierarchy.

不为A控制器调用viewWillDisappear方法,因为它保留在视图层次结构上。

#2


0  

It not run, because I forgot to add this line in A Controller:

它没有运行,因为我忘了在A Controller中添加这一行:

// b is a object of B ViewController

b.callBackViewWillAppearDelegate = self

It work now.

它现在工作。

#1


0  

The method viewWillDisappear is not called for A controller because this stays on the view hierarchy.

不为A控制器调用viewWillDisappear方法,因为它保留在视图层次结构上。

#2


0  

It not run, because I forgot to add this line in A Controller:

它没有运行,因为我忘了在A Controller中添加这一行:

// b is a object of B ViewController

b.callBackViewWillAppearDelegate = self

It work now.

它现在工作。