Swift 4在解除View Controller后调用ViewWillAppear

时间:2018-04-23 10:00:11

标签: ios swift segue

我想在解雇停留viewWillAppear后致电ViewController

ViewController1 - > Segue - > ViewController2

在VeiwController2中

1)

self.dismiss(animated: true, completion: nil)

2)。

 override func viewDidDisappear(_ animated: Bool) {

       ViewController1().viewWillAppear(true)

    }

在VeiwController1

调用viewWillAppear时,我的应用程序出现null错误。如何解雇overContext ViewController并以正确的方式调用viewWillAppear方法。

3 个答案:

答案 0 :(得分:5)

解除VC2时会自动调用viewWillAppear。删除: ViewController1().viewWillAppear(true)

尝试删除:

VC1中的

super.viewWillAppear(animated)viewDidAppear not getting called

它甚至会回到你的VC吗? self.dismiss在这里使用“Present Modally”segue。或者使用popViewController

嵌入NavigationBar

答案 1 :(得分:1)

yout模态应为.fullScreen

尝试一下:

let createAccounts = CreateAccounts();
        let navController = UINavigationController(rootViewController: createAccounts)
        navController.modalPresentationStyle = .fullScreen

答案 2 :(得分:0)

// Override this function in ViewController1
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)

 //Your code here will execute after viewDidLoad() or when you dismiss the child viewController  

}

我建议你完成ViewController的生命周期。 Apple documentation for ViewController life cycle