Is it possible to call a method when a tab bar icon is touched, even if its already the selected icon? I want to make it remove a sub view when touched if the subview is showing.
I’m sure there must be a way to do this because I see it in other apps, but I cannot find any documentation on it.
From Apple Documentation for UITabBarDelegate :
As you noticed I think, and as stated by Apple docs, this message is sent only when a tab is selected
An important note, there is already a (not-documented?) default
UIKitbehavior of tapping a selected tab bar button :So beware before overriding this default (and user expected) behavior, which is, generally, a bad idea.
Apple has probably hidden what you want to do in its
UIKitAPI, on purpose.But if you want anyway does this, here are some ideas:
.subviewstree to find (I expect, to be confirmed)UIButtons inherited classes (=privateUITabBarButtonsor something like) to add your target/selector pairs on TouchUp event (you might have to remove default behavior first, which might be tricky)UITabBar, but a custom class. I’m pretty sure there are ready-to-use open source components that mimicsUITabBar, but sorry, I never used/searched one.