1

In my tableView, when I press tab cell first time it calls viewDidLoad() but the other time that doesn't call viewDidLoad(). How to solve that problem. I want to call viewDidLoad() every time I press tab view in my code.

4
  • 2
    Why do you want viewDidLoad called every time? It should only be called once. Commented May 4, 2016 at 4:28
  • use viewWillAppear ..... Commented May 4, 2016 at 4:45
  • viewdidload is only called once in its life time and basically for one time initialization , if it is required to do this thing again whenever view appear , best place is viewWillAppear or viewDidAppear . Commented May 4, 2016 at 5:54
  • viewDidLoad will only be called once. If you want some code to run every time view appears you should use either viewWillAppear or viewDidAppear method depending on situation. Commented May 4, 2016 at 6:01

2 Answers 2

4

ViewDidLoad will be called when the view was loaded into memory. You want to use the ViewWillAppear function this will be called every time the view is about to get active.

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated);
}
Sign up to request clarification or add additional context in comments.

3 Comments

that's very useful answer. Thanks for your help.
Thank you so much .. Helped me
@RashwanL Answers No2 is useful.
3

In my opinion viewDidLoad() will called only one time, viewWillAppear() will be called everytime page is loaded. So you need to write source code to viewWillAppear() which might be call everytime.

Comments

Your Answer

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