Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call viewWillDisappear method in Tabbar Application having navigations also

I have created 5 Tabs in my application. In Tab1 i have UITableView. On didSelectRowAtIndexPath i am navigating to another UIView in which I am showing my all 5 Tabs. And I also play song in that navigated view.

Now when I click Back button in navigation and i again go to my original view, i am able to call viewWillDisappear (as expected and normal situation).

But when I click directly another tab then viewWillDisappear is not called in the navigated View. Why this Happens??

I have just thought in a way that when I directly clicks the another Tab then the view in Tab1 will call viewWillDisappear. But the navigated view will not call that method.

So what could be possible solutions?? kindly give some hints...

like image 967
DShah Avatar asked Dec 01 '22 01:12

DShah


2 Answers

I got the viewWillDisappear to work by calling

self.definesPresentationContext = true

in viewDidLoad()

Otherwise, viewWillDisappear wasn't getting called. And this is what I have in it:

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    self.searchController.active = false
    tableView.reloadData()
}

Hope this helps.

like image 97
C0D3 Avatar answered Dec 05 '22 09:12

C0D3


I think that you need to catch the event when you switch between tabs. When you switch from Tab1 to Tab2, as you expect, viewWillDisappear of Tab1 will not be called. Instead, the viewWillAppear of Tab2 will be called.

Else if you want to catch the event when you switch tabs, check this link.

like image 25
iOS Avatar answered Dec 05 '22 09:12

iOS