Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My viewDidAppear not called in view controller

It turns out that what I want to do is that when I come from a 3d shortcut, forcing the UITabBarController to choose an index, if I do this in the tab bar viewDidAppear() the problem is that the viewDidAppear() of my main UIViewController Embedded is not called, if I click again on the tab bar item then already if it is called. With the rest of the drivers does not happen, I understand why it is not the one that is first in the list of items in the UITabBarController.

Tab bar controller: (Here it comes)

override func viewDidAppear(_ animated: Bool) {
    if goTasks {
        self.selectedIndex = 0
    } else if goTodo {
        self.selectedIndex = 2
    } else if goProjects {
        self.selectedIndex = 3
    } else if goSearch {
        self.selectedIndex = 0
    }

}

My first UIViewController: (Not called this method)

override func viewDidAppear(_ animated: Bool) {
    print("Entry")
}

Is the problem override the methods? Any solution?

like image 568
Alejandro Avatar asked Mar 29 '17 11:03

Alejandro


People also ask

Why viewWillAppear is not called?

The Simple Answer. The technical reason for when viewWillAppear gets called is simple. Notifies the view controller that its view is about to be added to a view hierarchy. It can't be any view hierarchy — it has to be the one with a UIWindow at the root (not necessarily the visible window).

Is viewWillAppear always called?

viewWillAppear(_:)Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.

What is called after viewDidAppear?

viewDidAppear is called once you see the loaded view on screen. It is called after view appeared.

What triggers viewWillAppear?

The method viewWillAppear: is triggered in response to a change in the state of the application, indicating that the view controller is becoming “active.”


1 Answers

In your UITabBarController class viewDidAppear func , call it's super class, like this

 override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if goTasks {
            self.selectedIndex = 0
        } else if goTodo {
            self.selectedIndex = 2
        } else if goProjects {
            self.selectedIndex = 3
        } else if goSearch {
            self.selectedIndex = 0
        }

    }

After that, your first viewcontroller will call this method.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    print("Entry")
}
like image 178
Surjeet Singh Avatar answered Sep 29 '22 09:09

Surjeet Singh