0

I have a UITabBarController and a class named it ScreenLocker, in UITabBarController/ViewDidApear I initialize ScreenLocker with a call back, screen locker after c second or when app going to background should call this call back,

class TabBarViewController: UITabBarController {

override func viewDidLoad() {

}

override func viewDidAppear(_ animated: Bool) {
    lockAppCallBack()
}

func lockAppCallBack() {
    let callBack = {
        let myModalViewController = R.storyboard.authentication.authenticationViewController()
        ScreenLocker.isAutoLocked = true
        myModalViewController!.modalPresentationStyle = UIModalPresentationStyle.fullScreen
        myModalViewController!.modalTransitionStyle = UIModalTransitionStyle.coverVertical
        self.present(myModalViewController!, animated: true, completion: nil)
    }
    AuthenticationPatternPresenter.initScreenLocker(callBack: callBack)
}

ScreenLocker

class ScreenLocker: NSObject{
static var isAutoLocked = false
static let instance : ScreenLocker = {

    let instance = ScreenLocker()
    return instance
}()

var timer:Timer!
var time:Int!
var callBack = {

}
func _init(time:Int, callBack: @escaping () -> ()){

    self.time = time
    self.callBack = callBack
}

Each tab has a UINavigationController Everything is ok, but when I change UITabBarController's tab and navigate to next view and back to previous view, tab's ViewDidAppear doesn't call. When I removed Tab bar's ViewDidAppear every thing was ok, When I add again an empty ViewDidAppear in tab bar there was a same problem. Is there any problem with UITabBarController's ViewDidAppear? any suggestion?

2
  • 1
    ViewWillAppear will call with that. Commented Feb 27, 2019 at 7:43
  • Great, thanks a lot, I can not understand why? Could you please explain it in answer? or any related link? Commented Feb 27, 2019 at 8:17

1 Answer 1

1

You can use ViewWillAppear method for that.

For more info about app life cycle you can read HERE.

And HERE is the apple doc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.