В контроллере вида B используйте либо viewWillAppear
, либо viewDidAppear
. Там используйте isMovingToParent
и isBeingPresented
, чтобы увидеть, при каких условиях он появляется:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if !isBeingPresented && !isMovingToParent {
// this view controller is becoming visible because something that was covering it has been dismissed or popped
}
}
Ниже приведено более общее использование этих свойств, которое может оказаться полезным для людей:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isMovingToParent {
// this view controller is becoming visible because it was just push onto a navigation controller or some other container view controller
} else if isBeingPresented {
// this view controller is becoming visible because it is being presented from another view controller
} else if view.window == nil {
// this view controller is becoming visible for the first time as the window's root view controller
} else {
// this view controller is becoming visible because something that was covering it has been dismissed or popped
}
}