Search code examples
iosswiftuitabview

Do not reload content in the top view in a navigation on tab switch


I'm on a view (lets say VC1) which is at the top of navigation stack. I click on another Tab and come back to this view, content in VC1 reloads. How do I stop reloading content in this situation as reloading doesn't make any sense since view is already loaded with content.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    loadContent()    
}

Solution

  • You can't stop viewWillAppear to be called from 2 same actions like switching tab or poping a covering vc , so you need to remove viewWillAppear and assign a delegate for the vc you need to reload after it's pop to call loadContent