Определить, когда контроллер представления появляется из поп

Убедитесь, что вы закрыли свой класс.

Например, если у вас есть класс контроллера с методами, и случайно вы удаляете конечную скобку, которая закрывает весь класс, вы получите эту ошибку.

class someControler{
private $varr;
public $varu;
..
public function method {
..
} 
..
}// if you forget to close the controller, you will get the error
3
задан Josh Caswell 15 January 2019 в 21:45
поделиться

1 ответ

В контроллере 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
    }
}
0
ответ дан rmaddy 15 January 2019 в 21:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: