Is there a way to know in code when user has closed a modal by tapping the title? Apple's documentation states:
The title of the modal interface is set to the string Cancel unless the presented interface controller explicitly changes it using the
setTitle:
method. Tapping the title dismisses the interface automatically.
As far as I know there is now way to replace that title with a button.
I could fire a notification on didDeactivate()
or willDisappear()
but these will also be called when app enters background. So I could do an additional check in ExtensionDelegate's applicationWillResignActive()
to differentiate between user's action in my app or outside my app but this seems very fragile.
Are there any better ways?
Why would one need this?
In my case I have an initial screen where a user makes a choice. After the choice is made I present screens that contain data based on that choice.
I always want to show the data when the choice has been made. So I save the choice and present the modal on app launch when it is present.
But I don't want to show the data if the user has closed the data display. Yet I still want to display the choice made on the first screen. So I can't use the fact that the choice has been made to trigger modal displaying.
Hence I need to know if the modal has dissapeared because of user interaction in app or because the app got switched away.
Unfortunately, there is no other way to do so. But why do you need to add additional checks at
applicationWillResignActive()
? I think there is no need to do so.