使用 popOver 打开第二个视图时不会调用 viewWillDisapper

viewWillDisapper isn't called when opening a second view with popOver

在我的 mainVC 上,我有一个 TableView,带有一个按钮,可以打开第二个 VC,我可以在其中添加要显示的内容Table,类型为:“Present As Popover”。

我正在用 performSegue(withIdentifier:"goToOtherView", sender: nil 打开第二个 VC。

class FirstViewController: UIViewController {
    
    @IBOutlet weak var tableView: UITableView!
    
    var groupData = ["Data, Data1, Data2"]

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .green
        
        tableView.delegate = self
        tableView.dataSource = self
        
    }

    @IBAction func btnTapped(_ sender: Any) {
        
        performSegue(withIdentifier: "goToOtherView", sender: nil)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        print("FirstViewController will appear")
    }
    
    override func viewDidAppear(_ animated: Bool) {
        print("FirstViewController did appear")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        print("FirstViewController will disappear")
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        print("FirstViewController did disappear")
    }
    
}

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .blue

    }
    
    override func viewWillAppear(_ animated: Bool) {
        print("SecoundViewController will appear")
    }
    
    override func viewDidAppear(_ animated: Bool) {
        print("SecoundViewController did appear")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        print("SecoundViewController will disappear")
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        print("SecoundViewController did disappear")
    }
    
}

故事板

当我启动应用程序时

当我打开第二个VC时

当我关闭第二个VC时

FirstViewController willDisappeardidDisappear 永远不会被调用,甚至当 secondVC 关闭时 willAppeardidAppear我想在 FirstView willAppear/didAppear

时调用函数 tableView.reloadData()

它有点像 IOS 默认时钟应用程序,当你添加一个新的闹钟时。

快速猜测,但我认为这是因为演示模式是 pageSheet

你能试试把它改成全屏吗?

您还可以将 segue 配置更改为:

View disappear 不会被调用,因为视图并没有从 window

中完全消失